Hi Dave,
Thanks for your followup.
As for using XmlNamespaceManager to help executing XPATH in xmldocument
which contains namespace/prefix, I don't think it's the limitation of
net's XML interfaces. I'm sure this is a quite reasonable feature, here is
the reason why the XmlNamespaceManager is necessary:
When there is namespace in an xml document to scope elements in different
area(schemas), we use prefixs to identify namespaceURI. Like:
===============================
<?xml version="1.0" encoding="utf-8" ?>
<root xmlns="http://www.test.org"
xmlns:sns="http://www.test.org/sub">
<data>
<items>
<item id="1">
<sns:subItem sid="11">
</sns:subItem>
<sns:subItem sid="12">
</sns:subItem>
</item>
</items>
</data>
</root>
==============================
when we need to quer the <sns:subItem sid="11">
maybe we'll think that use the following xpath is quite normal:
//sns:subItem[@sid="11"]
However, according to the W3C XPATH1.0 specification. The full qualified
name of an element is actually it's namespaceURI(not prefix) combined with
its localname, that means the above path should be:
//http://www.test.org/sub:subItem[@sid="11"]
And as we known, namespace prefix is just a alias of namespaceURI, which
can be replaced by any other one as long as it can uniquely identity that
namespaceURI in the document. So .net framework provide the
XmlNamespaceManager which can help specify Namespace with arbitary prefix
value. For example, the above selection can be replaced by
XmlNamespaceManager mgr = new XmlNamespaceManager(new NameTable());
mgr.AddNamespace("aaa","http://www.test.org/sub");
string xpath = "//aaa:subItem[@sid='11']";
"sns" is just an alias, the actual idenitfy is "http://www.test.org/sub",
and the prefix in xpath should be able to be replaced by another alias.
(not only limited to "sns")
I'm not sure if those JAVA xml api is capable of this. However, at least I
think using prefix directly in xpath without any mapping info between
prefix---namespaceURI is not a reasonable behavior. Also, some times we're
not executing Xpath on a whole XmlDocument, just on a XmlNode , then where
does the API to look for the namespace /prefix declaration on the fly?
That's also why the .net using the XmlNamespaceManager to specify the
prefix---namespaceURI mapping.
#HOW TO: Specify Namespaces When You Use an XmlDocument to Execute XPath
Queries in Visual C# .NET
http://support.microsoft.com/default...b;en-us;318545
If you still have anything unclear, please feel free to post here. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)