I'm sure I'm missing something simple here but I've wrestled with it for a few days. I'm hoping someone can point out what I am missing.
I receive a XML message from an outside source in the following simplified format:
<root>
<A>
<B xmlns="http://www.something.com/Document>
<C>Value1</C>
<D>Value2</D>
<E>Value3</E>
</B>
</A>
<A>
<B xmlns="http://www.something.com/Document>
<D>Value5</D>
<E>Value6</E>
</B>
</A>
</root>
I'm trying to pull out the D elements.
I've tried:
XmlNodeList xmlResults = xdPayload.SelectNodes("//D")
This returned no results. Then thinking that the namespace was the issue I tried:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xdPayload.NameTable);
xnlResults = xdPayload.SelectNodes("//D", nsmgr);
Again no results. I didn't think I needed to add in the default namespace but when thinking smart doesn't work think stupid. So I tried this:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xdPayload.NameTable);
nsmgr.AddNamespace("", "http://www.something.com/Document");
xnlResults = xdPayload.SelectNodes("//D", nsmgr);
Still no results. I've tried more descriptive XPaths like "/root/A/B/D" and "/root/A/B[@xmlns="http://www.somewhere.com/Document"]/D" as well with no results as well.
I'm not sure what I'm missing here. Any help appreciated.