Class MultiLevelByNameAndTextSelector

  • All Implemented Interfaces:
    ElementSelector

    public class MultiLevelByNameAndTextSelector
    extends java.lang.Object
    implements ElementSelector
    ElementSelector that allows two elements to be compared if their name (including namespace URI, if any) and textual content is the same at a certain level of nesting.

    This means ElementSelectors.byNameAndText and MultiLevelByNameAndTextSelector(1) should lead to the same results.

    Any attribute values are completely ignored. Only works on elements with exactly one child element at each level.

    This class mostly exists as an example for custom ElementSelectors and may need to be combined inside a conditionalSelector in order to be useful for the document as a whole.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean ignoreEmptyTexts  
      private int levels  
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiLevelByNameAndTextSelector​(int levels)
      Uses element names and the text nested levels child elements deeper into the element to compare elements.
      MultiLevelByNameAndTextSelector​(int levels, boolean ignoreEmptyTexts)
      Uses element names and the text nested levels child elements deeper into the element to compare elements.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canBeCompared​(org.w3c.dom.Element controlElement, org.w3c.dom.Element testElement)
      Determine whether the two elements from the control and test XML can be compared.
      private org.w3c.dom.Node getFirstEligibleChild​(org.w3c.dom.Node parent)  
      private static boolean isText​(org.w3c.dom.Node n)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • levels

        private final int levels
      • ignoreEmptyTexts

        private final boolean ignoreEmptyTexts
    • Constructor Detail

      • MultiLevelByNameAndTextSelector

        public MultiLevelByNameAndTextSelector​(int levels)
        Uses element names and the text nested levels child elements deeper into the element to compare elements.

        Does not ignore empty text nodes.

      • MultiLevelByNameAndTextSelector

        public MultiLevelByNameAndTextSelector​(int levels,
                                               boolean ignoreEmptyTexts)
        Uses element names and the text nested levels child elements deeper into the element to compare elements.
        Parameters:
        ignoreEmptyTexts - whether whitespace-only textnodes should be ignored.
    • Method Detail

      • canBeCompared

        public boolean canBeCompared​(org.w3c.dom.Element controlElement,
                                     org.w3c.dom.Element testElement)
        Description copied from interface: ElementSelector
        Determine whether the two elements from the control and test XML can be compared.
        Specified by:
        canBeCompared in interface ElementSelector
      • getFirstEligibleChild

        private org.w3c.dom.Node getFirstEligibleChild​(org.w3c.dom.Node parent)
      • isText

        private static boolean isText​(org.w3c.dom.Node n)