I have an XML document that looks like this:
<kmsg xmlns="http://url1" xmlns:env="url1" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://location that does not exist.xsd"> <header> <env:envelope> <env:source branch="907" machine="0" password="J123"/> </env:envelope> </header> <body> <OrderResponse xmlns="urn:schemasbasdaorg:2000:orderResponse:xdr:3.01"> <SomeMoreNodes/> </OrderResponse> </body>
It has no schemas available, despite the fact that namespaces are specified (I get this from an external source, so I have no control). I parse it with XDocument, but keep getting null values ββfor elements outside the env namespace. I create an XDocument as follows:
XDocument Source = XDocument.Load("Testfile.xml"); XmlNamespaceManager oManager = new XmlNamespaceManager(new NameTable()); oManager.AddNamespace(String.Empty, "http://xml.kerridge.net/k8msg"); oManager.AddNamespace("env", "http://xml.kerridge.net/k8msgEnvelope");
Then I try to get the values:
? Source.XPathSelectElement ("// kmsg", oManager)
zero
? Source.XPathSelectElement ("// header", oManager)
zero
? Source.XPathSelectElement ("// env: source", oManager)
Chooses the correct node
I assume this is because I did not configure the namespace manager correctly, but I cannot figure out how to fix it. Any help would be great.
thank
c # xpath linq-to-xml xml-namespaces
Chris Surfleet Sep 15 2018-10-10T00: 00Z
source share