Beware of default namespaces. If you have one defined, then XPath needs to have 
a namespace mapped to a dummy prefix, and you have to qualify the prefix.  The 
following can be referenced using "/x/y".

<x><y>something...

But this has a problem:
<x xmlns="foo"><y>something...

Internally, XML tracks this like "/{foo}:x/{foo}:y".  What you have to do is 
tell the XPath processor to map some prefix, say 'a' to the namespace 'foo', 
then use "/a:x/a:y".  Note that the three following XML files are functionally 
identical:

<x xmlns="foo"><y>something...

<f:x xmlns:f="foo"><f:y>something...

<nnzz:x xmlns:nnzz="foo"><nnzz:y>something...

If you follow my instructions above, the XPath "/a:x/a:y" will get the element 
with the local-name 'y' every time.

You can also use "/*[local-name()='x']/*[local-name()='y']" but that's getting 
ugly...

Prefixes are a convenience for serialization purposes. The namespace is what is 
real.

-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Boydell, Stuart
Sent: Thursday, May 20, 2010 2:33 AM
To: U2 Users List
Subject: [U2] XPath queries

Is it just me being dull-witted or do XPath queries in XDOM not work by name?
Linux UV 10.2.7

I have spent quite a few hours trying to get something working and the only way 
I can get the node is to specify it by position rather than name.

For example I have to use this format to successfully query if an 'exception' 
element exists:
XDOMLocate(dh, '/*[1]/*[2]/*[last()]','',xh)

instead of specifying exactly what I'm looking for with what I believe should 
be valid XPath:
XDOMLocate(dh, '/ ABRPayloadSearchResults/response/exception','',xh)
or even better:
        XDOMLocate(dh, '//exception','',xh)

both of which return -1.
Anyone got any clues?

Cheers,
Stuart Boydell



_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to