RE: XmlDocument.SelectSingleNode XPathException
- From: v-schang@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Thu, 14 Apr 2005 05:37:15 GMT
Thanks for your reply Dave,
As you said:
===========
The "xmlns:sns="http://www.test.org/sub">" in the xml itself provides the
necessary information to turn:
//sns:subItem[@sid="11"]
into:
//http://www.test.org/sub:subItem[@sid="11"]
===========
yes, the XML Node or fragment did include the namespace declaraion.
However, this doesn't means that our XPATH can only use "sns" to idenity
the "http://www.test.org/sub" namespace. The "sns" is only an alias. So
the following two xml fragment should be identical (validate through schema)
#fragment A
<root xmlns:sns="http://www.test.org/sub">
<sns:item>
.......
</sns:item>
</root>
#fragment B
<root xmlns:aaa="http://www.test.org/sub">
<aaa:item>
.......
</aaa:item>
</root>
However, if we only use the
"//sns:item" xpath and haven't specify an prefix/ URI mapping, it
will only work( using the JAVA API you mentioned) in
fragment A , but not in fragment B( though framgment A is exactly the same
xml document as fragment B).
And when using .net's Xpath selection, since we specify the
XmlNamespaceManager which provide the prefix(in our xpath) ----
namespaceURI mapping , we can perform the xpath selection no matter the
namespace prefix is changed to anyone in the source xml document. Also,
the prefix in our XPATH can vary , such as :
//bbb:item using AddNamespace("bbb", "http://test.org/sub")
//ccc:item using AddNamespace("ccc", "http://test.org/sub")
Anyway, I think the prefix( in xpath ) is not simply an alias( it should
always has a namespaceURI mapped to it) , otherwise, the prefix will be
meaningless alone.
Just some of my understanding. 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.)
.
- References:
- XmlDocument.SelectSingleNode XPathException
- From: David Thielen
- RE: XmlDocument.SelectSingleNode XPathException
- From: Steven Cheng[MSFT]
- RE: XmlDocument.SelectSingleNode XPathException
- From: David Thielen
- RE: XmlDocument.SelectSingleNode XPathException
- From: Steven Cheng[MSFT]
- RE: XmlDocument.SelectSingleNode XPathException
- From: David Thielen
- RE: XmlDocument.SelectSingleNode XPathException
- From: Steven Cheng[MSFT]
- RE: XmlDocument.SelectSingleNode XPathException
- From: David Thielen
- XmlDocument.SelectSingleNode XPathException
- Prev by Date: Re: Posting XML to Server from ASP.NET/C# webapp
- Next by Date: help with SelectSingleNode
- Previous by thread: RE: XmlDocument.SelectSingleNode XPathException
- Next by thread: SOAP Call Retrieval
- Index(es):
Relevant Pages
|