Hi I have following code snippet which is working, when there is no namespace available but if i make it available then its return no values.
xml file : Person.xml
<?xml version="1.0" encoding="utf-8" ?>
<Persons>
<Person name="John Smith">
<Age>30</Age>
<Gender>Male</Gender>
</Person>
<Person name="Mike Folley">
<Age>25</Age>
<Gender>Male</Gender>
</Person>
<Person name="Lisa Carter">
<Age>22</Age>
<Gender>Female</Gender>
</Person>
</Persons>
Loading above xml file to xml document
string xmlstr1 = AppDomain.CurrentDomain.BaseDirectory + "Person.xml";
XmlDocument doc = new XmlDocument();
doc.Load(xmlstr1);
XmlNodeList personNodes = doc.DocumentElement.SelectNodes("Person");
if i add namespace for the document and try to get values using xath it wont work.
Adding name to root
<?xml version="1.0" encoding="utf-8" ?>
<Persons xmlns="www.google.com">
<Person name="John Smith">...
.....
Then i am trying the get value using following code but no result.
XmlNode root = doc.DocumentElement;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", root.NamespaceURI);
XmlNodeList node = doc.DocumentElement.SelectNodes("Person", nsmgr);
XmlDocument.Load("test.xml")to load the document is going to be simplest. (I'd still thoroughly recommend moving to LINQ to XML as soon as humanly possible. "This is my requirement" isn't really an explanation...)