I have an xml file were I want to get info by doing a xpath query with SelectSingleNode and SelectNodes.
.Net requires you to use namespacemanager, but I cant get it work. The query just gives me null.
When I take my namespace xmlns=".." from the root element away then it works.
Here is the code and xml file...could someone help me please?
c#:
try
{
XmlDocument doc =
new XmlDocument();doc.Load("sampleXML.xml");
System.Xml.XmlNamespaceManager nsmg = new System.Xml.XmlNamespaceManager(doc.NameTable);nsmg.AddNamespace("test", http://www.test.com);
//Lasketaan alignments:ien määrä tiedostossa int alignments;alignments = doc.SelectNodes("//test:Alignment", nsmg).Count; //return null
MessageBox.Show(alignments.ToString());
}
catch(Exception ex){
MessageBox.Show(ex.ToString());
}
xml:
Replies
Know the answer? Post it — somebody with the same question will find it here.