0

Hi everybody,

I have this XML file,,

<users type="array">
 <user>
  <id>12345567</id> 
  <name>Ronsna Stedinberg</name> 
  <screenname>Donnsax</screenname> 
  <location>New York</location> 
 </user>
 <user>
  <id>12345568</id> 
  <name>Sonsna Dtedinberg</name> 
  <screenname>Nonnsax</screenname> 
  <location>Las Angeles</location> 
 </user>  
</users>

and I wonder how can I read all the id's info in the xml?
(the <user> </user> is repeat 50 times, so I have 50 id's.)

Thanks.

Ron,

3
Contributors
3
Replies
17
Views
8 Years
Discussion Span
Last Post by shwetawaghmare
0

Use System.XML namespace DOM classes.

getElementsByTagName method.

.....      
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"c:\csnet\46\CSonsole\a1.xml");
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlNodeList lst = root.GetElementsByTagName("id");

  foreach (System.Xml.XmlNode n in lst)
        {
            Console.WriteLine(n.InnerText);  // print id text
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.