how to read the specific tag [modified]
-
hi all This is to read the tag line by line. using System.Xml; ... ... ... XmlTextReader reader = new XmlTextReader ("reader.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. Console.Write("<" + reader.Name); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } Console.ReadLine(); How do i read the specific tag if i just want to read all the tag that have this < big > tag? thank you
modified on Monday, April 13, 2009 3:36 AM
-
hi all This is to read the tag line by line. using System.Xml; ... ... ... XmlTextReader reader = new XmlTextReader ("reader.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. Console.Write("<" + reader.Name); Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. Console.WriteLine (reader.Value); break; case XmlNodeType.EndElement: //Display the end of the element. Console.Write("</" + reader.Name); Console.WriteLine(">"); break; } } Console.ReadLine(); How do i read the specific tag if i just want to read all the tag that have this < big > tag? thank you
modified on Monday, April 13, 2009 3:36 AM
use an XmlDocument[^] and the SelectNodes[^] method to search for specific nodes. This[^] article has a nice cheat sheet of the XPath syntax for searching for nodes.