LoadXML & NamespaceManager

B

Bruce Sandeman

Hi,
Is anyone able to help me? I have the following code and when I try to
create an XPathNavigator object it keeps returning null. any cunning
ideas?

private void loadXMLDoc(String xml)
{
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
namespaceManager = new
XmlNamespaceManager(xmlDoc.NameTable);
namespaceManager.AddNamespace("ns1",
"urn:soj-deltascheme-com.supplierinquiry.v1");
}

private String getFieldValue(String xpath)
{
return getFieldXPN(xpath).Value;
}

private XPathNavigator getFieldXPN(String xpath)
{
XPathNavigator xpn =
xmlDoc.CreateNavigator().SelectSingleNode(xpath, namespaceManager);
return xpn;
}

The XPath I am using is
"/ns1:Invoice/ns1:InvoiceDetail/ns1:CompanyNumber"
I have copied the xml into OxygenXML and then tested this xpath against
that within Oxygen and it works just fine. But for some reason in this
code it returns null instead of "3000".

thanks very much
cheers
Bruce
 
B

Bruce Sandeman

Sorry my brain had melted, not enough sleep.
I had my namespace wrong. it should've been
"urn:soj-deltascheme-com.invoiceapprovalv1.0"

cheers
Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top