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">thiele n</sns:subItem>
</item>
<item id="2">
<sns:subItem sid="21">shirle y</sns:subItem>
</item>
</items>
<mns:more>dav e thielen</mns:more>
</data>
</root>
1. If I do SelectSingleNod e("/root/data/items/item/@id") - I get no nodes
returned. This is the case if I create an XmlNamespaceMan ager or not.
2. If I do SelectSingleNod e("/root/data/items/item/sns:subItem/@sid") where
I have a namespace qualified node I get:
2a. If there is no XmlNamespaceMan ager I get an exception.
2b. If I add the following code:
XmlNamespaceMan ager context = new XmlNamespaceMan ager(doc.NameTa ble);
context.AddName space("sns", "http://www.test.org/sub");
node = doc.SelectSingl eNode(("/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 XmlNamespaceMan ager, 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