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. C#
  4. How to read the node from xml file in C#?

How to read the node from xml file in C#?

Scheduled Pinned Locked Moved C#
csharpxmlhelptutorialquestion
6 Posts 4 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.
  • N Offline
    N Offline
    nicolus
    wrote on last edited by
    #1

    i have an xml file in the following format i want to read a node's text in the following manner in C# but it is not giving any thing why? and how to do that? Pls help me. Here is my xml file ("withNsxml.xml")content: fgdfgdfgjkfjdg This is the code snippet i am using to read the text in "MD_Identification" node XmlDocument XDom = new XmlDocument(); XDom.Load(@"F:\withNsxml.xml"); XmlNamespaceManager XMLNSMgr = new XmlNamespaceManager(XDom.NameTable); XMLNSMgr.AddNamespace(string.Empty, "http://www.isotc211.org/2005/gmd"); XmlNodeList nodes1 = XDom.SelectNodes("md_metadata/md_identification", XMLNSMgr); foreach (XmlNode node in nodes1) { MessageBox.Show(node.InnerText ); } Thanks in advance.

    A N M 3 Replies Last reply
    0
    • N nicolus

      i have an xml file in the following format i want to read a node's text in the following manner in C# but it is not giving any thing why? and how to do that? Pls help me. Here is my xml file ("withNsxml.xml")content: fgdfgdfgjkfjdg This is the code snippet i am using to read the text in "MD_Identification" node XmlDocument XDom = new XmlDocument(); XDom.Load(@"F:\withNsxml.xml"); XmlNamespaceManager XMLNSMgr = new XmlNamespaceManager(XDom.NameTable); XMLNSMgr.AddNamespace(string.Empty, "http://www.isotc211.org/2005/gmd"); XmlNodeList nodes1 = XDom.SelectNodes("md_metadata/md_identification", XMLNSMgr); foreach (XmlNode node in nodes1) { MessageBox.Show(node.InnerText ); } Thanks in advance.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Better if you used

      Using System.XML
      

      and use XMLReader to Read XMLElement !!!! It will Solve your Problem !!!!

      Best Regards ----------------- Abhijit Jana View My CodeProject Articles "Success is Journey it's not a destination"

      N 1 Reply Last reply
      0
      • N nicolus

        i have an xml file in the following format i want to read a node's text in the following manner in C# but it is not giving any thing why? and how to do that? Pls help me. Here is my xml file ("withNsxml.xml")content: fgdfgdfgjkfjdg This is the code snippet i am using to read the text in "MD_Identification" node XmlDocument XDom = new XmlDocument(); XDom.Load(@"F:\withNsxml.xml"); XmlNamespaceManager XMLNSMgr = new XmlNamespaceManager(XDom.NameTable); XMLNSMgr.AddNamespace(string.Empty, "http://www.isotc211.org/2005/gmd"); XmlNodeList nodes1 = XDom.SelectNodes("md_metadata/md_identification", XMLNSMgr); foreach (XmlNode node in nodes1) { MessageBox.Show(node.InnerText ); } Thanks in advance.

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Use XMLDocument.GetElementsByTagName("md_identification") which returns XMLNodelist. Iterate through each node and print the InnerText.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        N 1 Reply Last reply
        0
        • A Abhijit Jana

          Better if you used

          Using System.XML
          

          and use XMLReader to Read XMLElement !!!! It will Solve your Problem !!!!

          Best Regards ----------------- Abhijit Jana View My CodeProject Articles "Success is Journey it's not a destination"

          N Offline
          N Offline
          nicolus
          wrote on last edited by
          #4

          but i want to read the inner text of the any node specified(using xpath) in the xml file.

          1 Reply Last reply
          0
          • N nicolus

            i have an xml file in the following format i want to read a node's text in the following manner in C# but it is not giving any thing why? and how to do that? Pls help me. Here is my xml file ("withNsxml.xml")content: fgdfgdfgjkfjdg This is the code snippet i am using to read the text in "MD_Identification" node XmlDocument XDom = new XmlDocument(); XDom.Load(@"F:\withNsxml.xml"); XmlNamespaceManager XMLNSMgr = new XmlNamespaceManager(XDom.NameTable); XMLNSMgr.AddNamespace(string.Empty, "http://www.isotc211.org/2005/gmd"); XmlNodeList nodes1 = XDom.SelectNodes("md_metadata/md_identification", XMLNSMgr); foreach (XmlNode node in nodes1) { MessageBox.Show(node.InnerText ); } Thanks in advance.

            M Offline
            M Offline
            Malcolm Smart
            wrote on last edited by
            #5

            Sort of an answer....

            <md_metadata xmlns:mynamespace="http://www.isotc211.org/2005/gmd">
            <md_identification> fgdfgdfgjkfjdg</md_identification>
            </md_metadata>

            The only way I got this to work was to either remove teh namespace concept altogether, or give the namespace a 'name' - 'mynamespace'. Not sure why - I've googled, but now ran out of time.... If you get to the bottom, please reply.

            Small angry dogs

            1 Reply Last reply
            0
            • N N a v a n e e t h

              Use XMLDocument.GetElementsByTagName("md_identification") which returns XMLNodelist. Iterate through each node and print the InnerText.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              N Offline
              N Offline
              nicolus
              wrote on last edited by
              #6

              Ya thats a very good alternative thanks for it. But still is there any way to get it with the Xpath as the parameter? Because my xml file contain multiple occurrances of some nodes and with in those nodes some Hierarchy levels are there so to extract them, if i use XPath mechanism then the nodes will come properly.

              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