org.apache.jmeter.util

## Class XPathUtil

- java.lang.Object
- - org.apache.jmeter.util.XPathUtil

-     public class XPathUtil
      extends java.lang.Object

  This class provides a few utility methods for dealing with XML/XPath.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `computeAssertionResult(AssertionResult result, org.w3c.dom.Document doc, java.lang.String xPathExpression, boolean isNegated)` Fills result
    `static java.lang.String` | `formatXml(java.lang.String xml)` Formats XML
    `static java.lang.String` | `getValueForNode(org.w3c.dom.Node node)`
    `static org.w3c.dom.Document` | `makeDocument(java.io.InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean reportErrors, boolean isXml, boolean downloadDTDs)` Utility function to get new Document
    `static org.w3c.dom.Document` | `makeDocument(java.io.InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXml, boolean downloadDTDs, java.io.OutputStream tidyOut)` Utility function to get new Document
    `static javax.xml.parsers.DocumentBuilder` | `makeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs)` Create a DocumentBuilder using the makeDocumentFactory func.
    `static org.w3c.tidy.Tidy` | `makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, java.io.StringWriter stringWriter)` Create a Tidy parser with the specified settings.
    `static void` | `putValuesForXPathInList(org.w3c.dom.Document document, java.lang.String xPathQuery, java.util.List<java.lang.String> matchStrings, boolean fragment)` Put in matchStrings results of evaluation
    `static void` | `putValuesForXPathInList(org.w3c.dom.Document document, java.lang.String xPathQuery, java.util.List<java.lang.String> matchStrings, boolean fragment, int matchNumber)` Put in matchStrings results of evaluation
    `static org.w3c.dom.NodeList` | `selectNodeList(org.w3c.dom.Document document, java.lang.String xPathExpression)` Extract NodeList using expression
    `static void` | `validateXPath(org.w3c.dom.Document document, java.lang.String xpathString)` Validate xpathString is a valid XPath expression

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### makeDocumentBuilder

          public static javax.xml.parsers.DocumentBuilder makeDocumentBuilder(boolean validate,
                                                                              boolean whitespace,
                                                                              boolean namespace,
                                                                              boolean downloadDTDs)
                                                                       throws javax.xml.parsers.ParserConfigurationException

      Create a DocumentBuilder using the makeDocumentFactory func.
      Parameters:
        `validate` - should the parser validate documents?
        `whitespace` - should the parser eliminate whitespace in element content?
        `namespace` - should the parser be namespace aware?
        `downloadDTDs` - if true, parser should attempt to resolve external entities
      Returns:
        document builder
      Throws:
        `javax.xml.parsers.ParserConfigurationException` - if `DocumentBuilder` can not be created for the wanted configuration

    - #### makeDocument

          public static org.w3c.dom.Document makeDocument(java.io.InputStream stream,
                                                          boolean validate,
                                                          boolean whitespace,
                                                          boolean namespace,
                                                          boolean tolerant,
                                                          boolean quiet,
                                                          boolean showWarnings,
                                                          boolean reportErrors,
                                                          boolean isXml,
                                                          boolean downloadDTDs)
                                                   throws javax.xml.parsers.ParserConfigurationException,
                                                          org.xml.sax.SAXException,
                                                          java.io.IOException,
                                                          TidyException

      Utility function to get new Document
      Parameters:
        `stream` - - Document Input stream
        `validate` - - Validate Document (not Tidy)
        `whitespace` - - Element Whitespace (not Tidy)
        `namespace` - - Is Namespace aware. (not Tidy)
        `tolerant` - - Is tolerant - i.e. use the Tidy parser
        `quiet` - - set Tidy quiet
        `showWarnings` - - set Tidy warnings
        `reportErrors` - - throw TidyException if Tidy detects an error
        `isXml` - - is document already XML (Tidy only)
        `downloadDTDs` - - if true, try to download external DTDs
      Returns:
        document
      Throws:
        `javax.xml.parsers.ParserConfigurationException` - when no `DocumentBuilder` can be constructed for the wanted configuration
        `org.xml.sax.SAXException` - if parsing fails
        `java.io.IOException` - if an I/O error occurs while parsing
        `TidyException` - if a ParseError is detected and `report_errors` is `true`

    - #### makeDocument

          public static org.w3c.dom.Document makeDocument(java.io.InputStream stream,
                                                          boolean validate,
                                                          boolean whitespace,
                                                          boolean namespace,
                                                          boolean tolerant,
                                                          boolean quiet,
                                                          boolean showWarnings,
                                                          boolean report_errors,
                                                          boolean isXml,
                                                          boolean downloadDTDs,
                                                          java.io.OutputStream tidyOut)
                                                   throws javax.xml.parsers.ParserConfigurationException,
                                                          org.xml.sax.SAXException,
                                                          java.io.IOException,
                                                          TidyException

      Utility function to get new Document
      Parameters:
        `stream` - - Document Input stream
        `validate` - - Validate Document (not Tidy)
        `whitespace` - - Element Whitespace (not Tidy)
        `namespace` - - Is Namespace aware. (not Tidy)
        `tolerant` - - Is tolerant - i.e. use the Tidy parser
        `quiet` - - set Tidy quiet
        `showWarnings` - - set Tidy warnings
        `report_errors` - - throw TidyException if Tidy detects an error
        `isXml` - - is document already XML (Tidy only)
        `downloadDTDs` - - if true, try to download external DTDs
        `tidyOut` - OutputStream for Tidy pretty-printing
      Returns:
        document
      Throws:
        `javax.xml.parsers.ParserConfigurationException` - if `DocumentBuilder` can not be created for the wanted configuration
        `org.xml.sax.SAXException` - if parsing fails
        `java.io.IOException` - if I/O error occurs while parsing
        `TidyException` - if a ParseError is detected and `report_errors` is `true`

    - #### makeTidyParser

          public static org.w3c.tidy.Tidy makeTidyParser(boolean quiet,
                                                         boolean showWarnings,
                                                         boolean isXml,
                                                         java.io.StringWriter stringWriter)

      Create a Tidy parser with the specified settings.
      Parameters:
        `quiet` - - set the Tidy quiet flag?
        `showWarnings` - - show Tidy warnings?
        `isXml` - - treat the content as XML?
        `stringWriter` - - if non-null, use this for Tidy errorOutput
      Returns:
        the Tidy parser

    - #### getValueForNode

          public static java.lang.String getValueForNode(org.w3c.dom.Node node)

      Parameters:
        `node` - `Node`
      Returns:
        String content of node

    - #### selectNodeList

          public static org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Document document,
                                                            java.lang.String xPathExpression)
                                                     throws javax.xml.transform.TransformerException

      Extract NodeList using expression
      Parameters:
        `document` - `Document`
        `xPathExpression` - XPath expression
      Returns:
        `NodeList`
      Throws:
        `javax.xml.transform.TransformerException` - when the internally used xpath engine fails

    - #### putValuesForXPathInList

          public static void putValuesForXPathInList(org.w3c.dom.Document document,
                                                     java.lang.String xPathQuery,
                                                     java.util.List<java.lang.String> matchStrings,
                                                     boolean fragment)
                                              throws javax.xml.transform.TransformerException

      Put in matchStrings results of evaluation
      Parameters:
        `document` - XML document
        `xPathQuery` - XPath Query
        `matchStrings` - List of strings that will be filled
        `fragment` - return fragment
      Throws:
        `javax.xml.transform.TransformerException` - when the internally used xpath engine fails

    - #### putValuesForXPathInList

          public static void putValuesForXPathInList(org.w3c.dom.Document document,
                                                     java.lang.String xPathQuery,
                                                     java.util.List<java.lang.String> matchStrings,
                                                     boolean fragment,
                                                     int matchNumber)
                                              throws javax.xml.transform.TransformerException

      Put in matchStrings results of evaluation
      Parameters:
        `document` - XML document
        `xPathQuery` - XPath Query
        `matchStrings` - List of strings that will be filled
        `fragment` - return fragment
        `matchNumber` - match number
      Throws:
        `javax.xml.transform.TransformerException` - when the internally used xpath engine fails

    - #### validateXPath

          public static void validateXPath(org.w3c.dom.Document document,
                                           java.lang.String xpathString)
                                    throws javax.xml.transform.TransformerException

      Validate xpathString is a valid XPath expression
      Parameters:
        `document` - XML Document
        `xpathString` - XPATH String
      Throws:
        `javax.xml.transform.TransformerException` - if expression fails to evaluate

    - #### computeAssertionResult

          public static void computeAssertionResult(AssertionResult result,
                                                    org.w3c.dom.Document doc,
                                                    java.lang.String xPathExpression,
                                                    boolean isNegated)

      Fills result
      Parameters:
        `result` - `AssertionResult`
        `doc` - XML Document
        `xPathExpression` - XPath expression
        `isNegated` - flag whether a non-match should be considered a success

    - #### formatXml

          public static java.lang.String formatXml(java.lang.String xml)

      Formats XML
      Parameters:
        `xml` - string to format
      Returns:
        String formatted XML

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.