Class XPath

java.lang.Object
com.avoka.fc.core.util.XPath

public class XPath extends Object
Provides an XPath implementation that "flips" the standard way of doing Jaxen around - it allows you to define the element once, and then evaluate multiple xpath expressions against that node.
  • Constructor Details

    • XPath

      public XPath(Document document)
      Create an XPath object based on the given document
      Parameters:
      document - a non-null XML document
    • XPath

      public XPath(Element documentElement)
      Create an XPath object based on the given element
      Parameters:
      documentElement - a non-null XML document element
  • Method Details

    • selectSingleNode

      public Element selectSingleNode(String xpath) throws ApplicationException
      Select a single node using the given XPath
      Parameters:
      xpath - the input XPath
      Returns:
      the element selected by the XPath
      Throws:
      ApplicationException - if there was an error evaluating the XPath
    • selectNodes

      public List selectNodes(String xpath) throws ApplicationException
      Select multiple nodes using the given XPath
      Parameters:
      xpath - the input XPath
      Returns:
      the list of elements selected by the XPath
      Throws:
      ApplicationException - if there was an error evaluating the XPath
    • stringValueOf

      public String stringValueOf(String xpath)
      Return the string value for the given path.
      Parameters:
      xpath - the input XPath
      Returns:
      the string value
    • getPathValue

      public String getPathValue(String path)
      Return the trimmed string value for the given path.
      Parameters:
      path - the input XPath
      Returns:
      the trimmed string value
    • setNodeValue

      public void setNodeValue(String path, String value)
      Set a node to a specified value
      Parameters:
      path - the XPath of an existing node
      value - the new value
    • setNodeValue

      public void setNodeValue(String path, Boolean value)
      Set a node to a specified boolean value
      Parameters:
      path - the XPath of an existing node
      value - the new value
    • setNodeValue

      public void setNodeValue(String path, Number value)
      Set a node to a specified numeric value
      Parameters:
      path - the XPath of an existing node
      value - the new value
    • setNodeValue

      public void setNodeValue(String path, String value, boolean optional)
      Set a node to a specified value
      Parameters:
      path - the XPath of an existing node
      value - the new value
      optional - Determines the behaviour if the node does not exist. If true, this will be silently ignored and nothing will be done; otherwise an ApplicationException will be thrown.