Hi;
If there are no namespaces this works fine for me. But if the xml has
namespaces, then I get either no node back or an exception.
Here is the sample xml:
<root xmlns="http://www.test.org"
xmlns:sns="http://www.test.org/sub"
xmlns:mns="http://www.test.org/mini">
<data>
<items>
<item id="1">
<sns:subItem sid="11">dave</sns:subItem>
<sns:subItem sid="12">thielen</sns:subItem>
</item>
<item id="2">
<sns:subItem sid="21">shirley</sns:subItem>
</item>
</items>
<mns:more>dave thielen</mns:more>
</data>
</root>
1. If I do SelectSingleNode("/root/data/items/item/@id") - I get no nodes
returned. This is the case if I create an XmlNamespaceManager or not.
2. If I do SelectSingleNode("/root/data/items/item/sns:subItem/@sid") where
I have a namespace qualified node I get:
2a. If there is no XmlNamespaceManager I get an exception.
2b. If I add the following code:
XmlNamespaceManager context = new XmlNamespaceManager(doc.NameTable);
context.AddNamespace("sns", "http://www.test.org/sub");
node = doc.SelectSingleNode(("/root/data/items/item/sns:subItem/@sid",
context);
Then I get no nodes returned (but at least no exception is thrown).
I tested all of the in XmlSpy and the xpath works there as expected.
So what is going on?
First off, even if I add the namespaces, I still can't get any node
returned. Both those with namespaces and those without evaluate to no nodes.
Second, why does it throw an exception if I don't create a namespace
manager? The namespaces exist in the xml file and by definition, those
mappings should be used. Also, to quote from
http://msdn.microsoft.com/library/de...edprefixes.asp
"If the msbooks namespace was not added to the XmlNamespaceManager, and if it
is not in the name table of the document, then an exception is thrown." So
there should be no exception thrown for namespaces that are defined in the
document.
Help please - this makes no sense to me.
--
thanks - dave