From: Stefan B. <bo...@ap...> - 2011-09-05 10:15:10
|
On 2011-09-05, Mirko Schmidt wrote: > Since I have a deep hierarchical structure I need recursive comparison > as provided by ElementNameAndAttributeQualifier or > ElementNameAndTextQualifier. However, since the differences are not > solely expressed as text or attribute differences, these element > qualifiers can't be used. When I use ElementNameAndAttributeQualifier, > then only the species nodes are found to be equal. On the other hand, if > I use ElementNameAndTextQualifier only the nodes tag0:ci are detected as > equal. > Is there a way to combine these two qualifiers? Not with any of the existing ElementQualifiers. Even if we had some sort of composite ElementQualifier that likely wouldn't work out too well - creating too many matches for elements with similar attributes or text content but differences in the other part. In the end you will want to say "match attributes for the species elements and nested text for the ci elements" and there is no way to do that without writing custom code. Fortunately it shouldn't be too difficult to write an implementation of ElementQualifier yourself, just look at the code of either of the two qualifiers you have identified. You could simply create instances of either of the two ElementQualifiers in your own implementation and then dispatch to the "correct" instance based on the element name of the current node in qualifyForComparison. Something like boolean qualifyForComparison(Element control, Element test) { if ("li".equals(control.getLocalName())) { return nameAndAttr.qualifyForComparison(control, test); } return nameAndText.qualifyForComparison(control, test); } It would become more difficult if you need more context information (i.e. you'd only want to compare attributes on li elements that have an species element somewhere up in their parent chain). Stefan |