I am looking for some help retrieving xpath expressions using the
getUniquePath() method.  I am trying to retrieve the absolute xpath
expression from a another xpath expression that has a predicate condition.
However, I need to have the xpath in a human readable form without the
name()  function in the returned xpath, as this is be used for reporting
purposes.

e.g. my xml looks like

<a xmlns="http://namespace"; xmlns:ns="http:namespace" >;
      <b>
             <c>1234</c>
             <c>something else</c>
       </b>
 </a>

Note I have the same namespace declared as the prefixed and default
namespace.
The xpath expression will look something like this

String xpath = /ns:a/ns:b:/ns:c[.=1234]

Node node = document.getSingleNode ( xpath );
String uniquePath = node.getUniquePath ();

when I use the above code I get an xpath expression that looks like

/*[name()=a]/*[name()=b]/*[name()=c][1].

Unfortunately I cannot control what the xml data specially to include
prefixes and also I am unable to modify the initial xpath.

However, if I modify the data to look like

<ns:a xmlns="http://namespace"; xmlns:ns="http:namespace" >;
      <ns:b>
             <ns:c>1234</ns:c>
             <ns:c>something else</ns:c>
       </ns:b>
 </ns:a>

the returned expression looks great -
/ns:a/ns:b/ns:c[1] - which is just what I am looking for.

I could parse and pattern match the xpath containing the name function to
make it look like the later, however that is going to be last resort.
Is there anything I can do with the prefix mapping or contexts or xpath
reporting to let dom4j handle the xpath reporting.

thanks in advance

Ismail









-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to