XML With C#
XML / XSL
2
Posts
2
Posters
0
Views
1
Watching
-
how i can get value of tagin xml file with C# codes.
example
: i wanna get value ofHello
-
how i can get value of tagin xml file with C# codes.
example
: i wanna get value ofHello
class Program
{
class Sample
{
public Sample()
{
string xmlString = "<xml><item>a<!--Item A--></item><item>b<!--Item B--></item><item>b<!--Item C--></item></xml>";XmlDocument document = new XmlDocument(); document.LoadXml(xmlString); //Navigate throgh all the nodes and check if a node is a comment Console.WriteLine("Method 1"); XmlNodeList nodes = document.SelectNodes("xml/item"); foreach (XmlNode childnode in nodes) { if (childnode.LastChild.NodeType == XmlNodeType.Comment) { Console.WriteLine(childnode.LastChild.InnerText); } } //Using Exact XQuery Console.WriteLine("\\n\\nMethod 2"); nodes = document.SelectNodes("xml/item/comment()"); foreach (XmlNode childnode in nodes) { Console.WriteLine(childnode.InnerText); } } } static void Main(string\[\] args) { Sample sample = new Sample(); Console.ReadLine(); }
}
Hope it helps!