How to read the node from xml file in C#?
-
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.
-
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.
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"
-
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.
Use
XMLDocument.GetElementsByTagName("md_identification")
which returnsXMLNodelist
. Iterate through each node and print theInnerText
.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
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"
-
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.
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
-
Use
XMLDocument.GetElementsByTagName("md_identification")
which returnsXMLNodelist
. Iterate through each node and print theInnerText
.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
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.