Class XPath

  • All Implemented Interfaces:
    Serializable

    public final class XPath
    extends Object
    implements Serializable
    A simple implementation of XPath.

    The subset supported by this implementation is the subset required to implement W3C XML Schema validation plus the support for absolute XPaths (W3C XMLSchema only requires supporting relative XPaths).

    See Also:
    Serialized Form
    • Method Detail

      • fromString

        public static XPath fromString​(String s,
                                       PrefixToNamespace prefixToNS,
                                       boolean allowDefaultNS)
        Parses specified string as a XPath. Syntax may be abbreviated or not.
        Parameters:
        s - string to be parsed
        prefixToNS - map used to get namespaces corresponding to prefixes found in string; may be null
        allowDefaultNS - when parsing an element name having no prefix, use the default namespace if any
        Returns:
        a XPath or null if string has syntax errors or contains unknown prefixes.
        See Also:
        Name.parse(java.lang.String, boolean, com.xmlmind.xml.name.PrefixToNamespace)
      • getPaths

        public Path[] getPaths()
        Returns the list of Paths composing this XPath. A XPath is a union of Paths (that is, Path|Path ... |Path).
      • sameAs

        public boolean sameAs​(XPath other)
        Compares this XPath to the specified one but unlike equals(java.lang.Object) the order of Paths within compared XPaths is not significant.
      • select

        public XNode[] select​(Tree tree)
        Returns nodes or attributes selected by this XPath in specified subtree.
        Parameters:
        tree - subtree to be searched
        Returns:
        A possibly empty array of nodes or attributes selected by this XPath
        See Also:
        Node, Attribute
      • select

        public XNode[] select​(Tree tree,
                              boolean attributePlaceholder)
        Returns nodes or attributes selected by this XPath in specified subtree.
        Parameters:
        tree - subtree to be searched
        attributePlaceholder - if false: add an Attribute to returned array only if the XPath has successfully selected this attribute.

        if true: when the element part of the XPath (example: /html/body//pre in /html/body//pre/@class) has successfully selected an Element which does not have the attribute specified by the XPath, add anyway an Attribute with a null value to returned array.

        Returns:
        A possibly empty array of nodes or attributes selected by this XPath
        See Also:
        Node, Attribute
      • union

        public static XNode[] union​(XNode[] set1,
                                    XNode[] set2)
        Returns the union of specified sets.
        Parameters:
        set1 - an array of nodes or attributes
        set2 - another array of nodes or attributes
        Returns:
        union of specified sets
      • match

        public boolean match​(XNode xnode)
        Tests if this XPath matches specified node or attribute.
        Parameters:
        xnode - node or attribute to be tested
        Returns:
        true if this XPath matches specified node or attribute; false otherwise