On 2010-08-21, Lanam, Jeff wrote:

> Alternatively, I could use a method that compares an abbreviated
> reference like the one above, with an expanded one.

> In the example above, getXPathLocation returns
>  /mydoc[1]/child[1]/city[1]/text()[1] . I need a way to determine that
> this is equivalent to "//chi...@name='Dick']/city".

This is pretty hard to do without using a full XPath engine on the
documents you compare - I hoped James had an idea, but now I'll try to
jump in.

Except in really trivial cases you can't say whether two XPath
expression yield the same node(s) (or even just intersecting sets of
nodes) without the context of the document you want to apply the XPath
to.

When you receive the Difference, you get a Node instance as well as the
XPath.  The XPath doesn't provide enough information for your
requirements, you'd have to travel up (Node#getParentNode) to the
"child" element and then consult its name attribute.

It may be easier to apply your XPath expression to the document
(Node#getOwnerDocument) and see whether the Node at hand is part of the
NodeLists that matches the XPath.  You could use
org.custommonkey.xmlunit.XMLUnit.newXpathEngine() for this or JAXP
directly (see the javax.xml.xpath namespace).

In your example the answer would be "no" since the city element matches
the XPath expression not its nested text which is the Node you receive
in the Difference - you may need to adapt here.

Stefan

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Xmlunit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xmlunit-general

Reply via email to