Class XPathUtils

java.lang.Object
gov.nasa.pds.registry.common.util.xml.XPathUtils

public class XPathUtils extends Object
Utility class to work with XPath API.
Author:
karpenko
  • Constructor Details

    • XPathUtils

      public XPathUtils()
      Constructor.
  • Method Details

    • compileXPath

      public static XPathExpression compileXPath(XPathFactory xpf, String str) throws Exception
      Compile XPath
      Parameters:
      xpf - XPath factory
      str - XPath string value
      Returns:
      Compiled XPath
      Throws:
      Exception - Generic exception
    • getStringValue

      public static String getStringValue(Document doc, XPathExpression expr) throws Exception
      Get string value by XPath.
      Parameters:
      doc - XML document
      expr - an XPath
      Returns:
      a string value
      Throws:
      Exception - Generic exception
    • getStringList

      public static List<String> getStringList(Document doc, XPathExpression expr) throws Exception
      Get a list of string values by XPath.
      Parameters:
      doc - XML document
      expr - an XPath
      Returns:
      a list
      Throws:
      Exception - Generic exception
    • getStringSet

      public static Set<String> getStringSet(Document doc, XPathExpression expr) throws Exception
      Get a set of string values by XPath.
      Parameters:
      doc - XML document
      expr - an XPath
      Returns:
      a set
      Throws:
      Exception - Generic exception
    • getStringList

      public List<String> getStringList(Document doc, String xpath) throws Exception
      Get a list of string values by XPath.
      Parameters:
      doc - XML document
      xpath - an XPath
      Returns:
      a list
      Throws:
      Exception - Generic exception
    • getStringSet

      public Set<String> getStringSet(Document doc, String xpath) throws Exception
      Get a set of string values by XPath.
      Parameters:
      doc - XML document
      xpath - an XPath
      Returns:
      a set
      Throws:
      Exception - Generic exception
    • getStringArray

      public static String[] getStringArray(Document doc, XPathExpression expr) throws Exception
      Get an array of string values by XPath.
      Parameters:
      doc - XML document
      expr - an XPath
      Returns:
      an array
      Throws:
      Exception - Generic exception
    • getNodeList

      public static NodeList getNodeList(Object item, XPathExpression expr) throws Exception
      Get node list by XPath.
      Parameters:
      item - parent item
      expr - an XPath
      Returns:
      Node list
      Throws:
      Exception - Generic exception
    • getNodeList

      public NodeList getNodeList(Object item, String xpath) throws Exception
      Get node list by XPath.
      Parameters:
      item - parent item
      xpath - an XPath
      Returns:
      Node list
      Throws:
      Exception - Generic exception
    • getNodeCount

      public int getNodeCount(Object item, String xpath) throws Exception
      Get node count by XPath.
      Parameters:
      item - parent item
      xpath - an XPath
      Returns:
      Node count
      Throws:
      Exception - Generic exception
    • getFirstNode

      public Node getFirstNode(Object item, String xpath) throws Exception
      Get first node by XPath.
      Parameters:
      item - Parent item
      xpath - an XPath
      Returns:
      a Node
      Throws:
      Exception - Generic exception