I am struggling retrieving a node from an XML document which has a different namespace to the rest of the document.
This is the XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:infData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>danielormisher.co.uk</domain:name>
<domain:roid>50798439-UK</domain:roid>
<domain:registrant>10DBFAD79B81CCDE</domain:registrant>
</domain:infData>
</resData>
<extension>
<domain-nom-ext:infData xmlns:domain-nom-ext="http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0" xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0 domain-nom-ext-1.0.xsd">
<domain-nom-ext:reg-status>Registered until expiry date.</domain-nom-ext:reg-status>
<domain-nom-ext:auto-bill>30</domain-nom-ext:auto-bill>
</domain-nom-ext:infData>
</extension>
</response>
</epp>
In the XML above, if I try to select the <domain:infData> element, which shares a namespace with the root element like so:
namespaces.AddNamespace("domain", "urn:ietf:params:xml:ns:domain-1.0");
var children = doc.SelectSingleNode("/ns:epp/ns:response/ns:resData/domain:infData", namespaces);
The node is selected fine. However, if I attempt to select the node <domain-nom-ext:infData>, which has a different namespace to the root like so:
namespaces.AddNamespace("domain", "urn:ietf:params:xml:ns:domain-1.0");
namespaces.AddNamespace("domain-nom-ext", "http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1");
children = doc.SelectSingleNode("/ns:epp/ns:response/ns:extension/domain-nom-ext:infData", namespaces);
I just get a null response. Can anyone point out what I am doing wrong??
Your XML sample has
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.0, your code uses a slightly different namespacehttp://www.nominet.org.uk/epp/xml/domain-nom-ext-1.1(i.e.1.1instead of1.0. That suffices to make your code select no element as you will need to use exactly the same namespace name.