The confusion that I had was that I initially thought that you have to specify the exact prefix that is used in the XML document in your xpath expression.
As it turns out and mentioned by Jeff Greff ... you can create a PrefixResolver that resolves the prefix that you used in the xpath expression to a given namespace URI, and that the prefix that you use in the xpath expression and in the PrefixResolver does NOT have to match the prefix in the actual XML document.


After that was cleared, then things are working as I expected.

Of course, there is a caveat there that Jeff mentioned, but I'll leave it at that.


Brenda Bell wrote:

Jesus M. Salvo Jr. wrote:


I have also tried using the XPathNSResolverImpl instead of PrefixResolverDefault.
I still have to specify the prefix in the xpath expression.


Anyone ...help please!


I've been watching this thread from the start and believe that part of the confusion has to do with namespaces in general -- frankly, it's one of the most misunderstood XML concepts.

You really have to think about your source document in more concrete terms. Namespaces are not a simple decoration -- they are a necessary means of establishing element "ownership" and distinguishing between two elements that may have the same name but mean entirely different things.

Just because you have a priori knowledge that there are no conflicts in your source document doesn't mean you get to break the rules. In XPath, you get to ask certain types of questions... one of them being "give me element x". Asking for plain element x is asking for the element x that is not associated with any namespace. If you want an element x that has been associated with a namespace, you have to include the namespace when you ask the question... not because there are conflicts in your document but because the potential for conflicts exists in general.

That said... it would be nice if XPath processors allowed you to ask the question "give me element x in any namespace". I'm new to Xalan, but have worked with other parsers -- none of which support a simple syntax for doing this. AFAIK, the only way to do this is to ask for "/*[local-name()='x']" which is much less efficient.

Namespaces are there to help you... really!!! Don't get tied up in the prefixes -- they are a convenience. If you get in the habit of declaring your own prefixes for namespace URI's that you need to consume in your program, you'll developer more robust XML applications.

Brenda
http://opensource.theotherbell.com




--
Jesus M. Salvo Jr.
Mobile Internet Group Pty Ltd
(formerly Softgame International Pty Ltd)
M: +61 409 126699
T: +61 2 94604777
F: +61 2 94603677

PGP Public key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0BA5348




Reply via email to