Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML With C#

XML With C#

Scheduled Pinned Locked Moved XML / XSL
csharpxmltutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jojoba2010
    wrote on last edited by
    #1

    how i can get value of tagin xml file with C# codes. example : i wanna get value of Hello

    V 1 Reply Last reply
    0
    • J jojoba2010

      how i can get value of tagin xml file with C# codes. example : i wanna get value of Hello

      V Offline
      V Offline
      vivasaayi
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups