Package org.appng.api

Class XPathProcessor

    • Constructor Detail

      • XPathProcessor

        public XPathProcessor​(String url)
                       throws IOException
        Create a new XPathProcessor from the given URL.
        Parameters:
        url - the URL
        Throws:
        IOException - if an error occurs while reading the XML-document from the URL
      • XPathProcessor

        public XPathProcessor​(URL url)
                       throws IOException
        Create a new XPathProcessor from the given URL.
        Parameters:
        url - the URL
        Throws:
        IOException - if an error occurs while reading the XML-document from the URL
    • Method Detail

      • setNamespace

        public void setNamespace​(String prefix,
                                 String namespace)
        Sets the namespace and the prefix to use for that namespace.
        Example:
         XPathProcessor xpath = ...;
         xpath.setNamespace("appng", "http://www.appng.org/schema/platform");
         xpath.getNode("/appng:platform//appng:action[@id=\"foo\"]")
         
        Parameters:
        prefix - the prefix
        namespace - the namespace
      • getXml

        public String getXml​(Node node)
        Returns the XML-fragment represented by the given Node.
        Parameters:
        node - the Node
        Returns:
        the XML-fragment
      • getXml

        public String getXml​(NodeList nodes)
        Returns the XML-fragment represented by the given NodeList.
        Parameters:
        nodes - the NodeList
        Returns:
        the XML-fragment
      • getString

        public String getString​(String xpathExpression)
        Parses the given xpathExpression to retrieve a String.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the String retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getString

        public String getString​(Node node,
                                String xpathExpression)
        Parses the given xpathExpression to retrieve a String.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the String retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getBoolean

        public Boolean getBoolean​(String xpathExpression)
        Parses the given xpathExpression to retrieve a Boolean.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the Boolean retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getBoolean

        public Boolean getBoolean​(Node node,
                                  String xpathExpression)
        Parses the given xpathExpression to retrieve a Boolean.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the Boolean retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNumber

        public Number getNumber​(String xpathExpression)
        Parses the given xpathExpression to retrieve a Number.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the Number retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNumber

        public Number getNumber​(Node node,
                                String xpathExpression)
        Parses the given xpathExpression to retrieve a Number.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the Number retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNode

        public Node getNode​(String xpathExpression)
        Parses the given xpathExpression to retrieve a Node.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the Node retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNode

        public Node getNode​(Node node,
                            String xpathExpression)
        Parses the given xpathExpression to retrieve a Node.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the Node retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getElement

        public Element getElement​(String xpathExpression)
        Parses the given xpathExpression to retrieve an Element.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the Element retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getElement

        public Element getElement​(Node node,
                                  String xpathExpression)
        Parses the given xpathExpression to retrieve an Element.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the Element retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNodes

        public NodeList getNodes​(String xpathExpression)
        Parses the given xpathExpression to retrieve a NodeList.
        Parameters:
        xpathExpression - the xpath-expression
        Returns:
        the NodeList retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • getNodes

        public NodeList getNodes​(Node node,
                                 String xpathExpression)
        Parses the given xpathExpression to retrieve a NodeList.
        Parameters:
        node - the Node to apply the expression to
        xpathExpression - the xpath-expression
        Returns:
        the NodeList retrieved from the xpathExpression (may be null), or null if the expression could not be parsed.
      • newAttribute

        public Attr newAttribute​(String name,
                                 String value)
        Creates a new Attribute.
        Parameters:
        name - the name of the attribute
        value - the value of the attribute
        Returns:
        the new Attribute.
      • newElement

        public Element newElement​(String tagName)
        Creates a new Element.
        Parameters:
        tagName - the tag-name for the element
        Returns:
        the new Element
      • newText

        public Text newText​(String tagName)
        Creates a new Text.
        Parameters:
        tagName - the tag-name for the text
        Returns:
        the new Text