locked
xelement class question RRS feed

  • Question

  • is there a way to place a xml string into a xelement object so I can query the element data by the tag attribute?

    my xml string looks like this:

    <encrypt><element tag="0010,0010">John^Doe</element><element tag="0010,0020">123-45-6789</element><element tag="0010,0030">20100526</element><element tag="0010,1010">30Y</element></encrypt>


    chuckdawit
    Wednesday, May 26, 2010 11:57 PM

Answers

  • Hi chuckdawit,

     

    Yes, we can pass the XML string value to the static method XElement.Parse().  Then if we want to retrieve the element value where tag attribute is “0010,0010”, we can use such a query:

    ==============================================================================

    string value = "<encrypt><element tag=\"0010,0010\">John^Doe</element><element tag=\"0010,0020\">123-45-6789</element><element tag=\"0010,0030\">20100526</element><element tag=\"0010,1010\">30Y</element></encrypt>";

     

    var element = XElement.Parse(value);

     

    var query = from el in element.Elements("element")

                where el.Attribute("tag").Value == "0010,0010"

                select el.Value;

    ==============================================================================

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 27, 2010 1:35 AM
    Moderator
  • Hi chuckdawit,

     

    I am writing to check the status of the issue on your side.  Would you mind letting me know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by witdaj Thursday, June 3, 2010 2:01 AM
    Tuesday, June 1, 2010 1:17 AM
    Moderator

All replies

  • Hi chuckdawit,

     

    Yes, we can pass the XML string value to the static method XElement.Parse().  Then if we want to retrieve the element value where tag attribute is “0010,0010”, we can use such a query:

    ==============================================================================

    string value = "<encrypt><element tag=\"0010,0010\">John^Doe</element><element tag=\"0010,0020\">123-45-6789</element><element tag=\"0010,0030\">20100526</element><element tag=\"0010,1010\">30Y</element></encrypt>";

     

    var element = XElement.Parse(value);

     

    var query = from el in element.Elements("element")

                where el.Attribute("tag").Value == "0010,0010"

                select el.Value;

    ==============================================================================

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 27, 2010 1:35 AM
    Moderator
  • Hi chuckdawit,

     

    I am writing to check the status of the issue on your side.  Would you mind letting me know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by witdaj Thursday, June 3, 2010 2:01 AM
    Tuesday, June 1, 2010 1:17 AM
    Moderator