Answered Loading and Reading XML at runtime

  • Saturday, February 02, 2013 11:28 AM
     
     

    Hi,

         I have functionality in which an XML file is generated at run time and stored to an string and from that XML file i would like to read the value of the "ID" which is bold out. Help me out with sample code or an link.

    And the XML is as follows

    <?xml version="1.0" encoding="UTF-8"?>
    <entry xmlns="http://www.w3.org/2005/Atom">
      <id>http://www.test.com/ws/customers/example@example.com/lists/222</id>
      <title type="text"></title>
      <author></author>
      <updated>2013-02-02T09:18:08.313Z</updated>
      <content type="application/vnd.ctct+xml">
        <ContactList xmlns="http://www.test.com/ns/1.0/" id="http://www.test.com/ws/customers/example@example.com/lists/222">
          <OptInDefault>false</OptInDefault>
          <Name>CB_29_2/2/2013 2:47:59 PM</Name>
          <SortOrder>13</SortOrder>
          <ShortName>CB_29_2/2/2013 2:47:59 PM</ShortName>
          <DisplayOnSignup>No</DisplayOnSignup>
          <Members id="http://www.test.com/ws/customers/example@example.com/lists/222/members"></Members>
        </ContactList>
      </content>
      <link href="/ws/customers/example@example.com/lists/222" rel="edit"></link>
    </entry>


    Regards, Dillu


    • Edited by dillu Saturday, February 02, 2013 11:29 AM
    •  

All Replies

  • Saturday, February 02, 2013 11:55 AM
     
     Answered

    With .NET 3.5 and later you can use LINQ to XML :

    XDocument doc = XDocument.Parse(stringWithXml);

    XNamespace atom = "http://www.w3.org/2005/Atom";

    string id = (string)doc.Root.Element(atom + "id");


    MVP Data Platform Development My blog

    • Marked As Answer by dillu Saturday, February 02, 2013 1:54 PM
    •  
  • Saturday, February 02, 2013 1:55 PM
     
     
    Perfect.....Thanks..

    Regards, Dillu