Package org.apache.jmeter.util
Class XPathUtil
java.lang.Object
org.apache.jmeter.util.XPathUtil
This class provides a few utility methods for dealing with XML/XPath.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidcomputeAssertionResult(AssertionResult result, Document doc, String xPathExpression, boolean isNegated) Fills resultstatic voidcomputeAssertionResultUsingSaxon(AssertionResult result, String xmlFile, String xPathQuery, String namespaces, Boolean isNegated) static StringFormats XMLgetNamespaces(String xml) Compute namespaces for XMLstatic net.sf.saxon.s9api.Processorstatic StringgetValueForNode(Node node) static DocumentmakeDocument(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 Documentstatic DocumentmakeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXml, boolean downloadDTDs, OutputStream tidyOut) Utility function to get new Documentstatic DocumentBuildermakeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs) Create a DocumentBuilder using the makeDocumentFactory func.static org.w3c.tidy.TidymakeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter) Create a Tidy parser with the specified settings.namespacesParse(String namespaces) static voidputValuesForXPathInList(Document document, String xPathQuery, List<? super String> matchStrings, boolean fragment) Put in matchStrings results of evaluationstatic voidputValuesForXPathInList(Document document, String xPathQuery, List<? super String> matchStrings, boolean fragment, int matchNumber) Put in matchStrings results of evaluationstatic voidputValuesForXPathInListUsingSaxon(String xmlFile, String xPathQuery, List<? super String> matchStrings, boolean fragment, int matchNumber, String namespaces) static NodeListselectNodeList(Document document, String xPathExpression) Extract NodeList using expressionstatic voidvalidateXPath(Document document, String xpathString) Validate xpathString is a valid XPath expressionstatic voidvalidateXPath2(Document document, String xpathString, String namespaces) Validate xpathString is a valid XPath expression
- 
Method Details- 
getProcessorpublic static net.sf.saxon.s9api.Processor getProcessor()
- 
makeDocumentBuilderpublic static DocumentBuilder makeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs) throws 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:
- ParserConfigurationException- if- DocumentBuildercan not be created for the wanted configuration
 
- 
makeDocumentpublic static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean reportErrors, boolean isXml, boolean downloadDTDs) throws ParserConfigurationException, SAXException, 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:
- ParserConfigurationException- when no- DocumentBuildercan be constructed for the wanted configuration
- SAXException- if parsing fails
- IOException- if an I/O error occurs while parsing
- TidyException- if a ParseError is detected and- report_errorsis- true
 
- 
makeDocumentpublic static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXml, boolean downloadDTDs, OutputStream tidyOut) throws ParserConfigurationException, SAXException, 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:
- ParserConfigurationException- if- DocumentBuildercan not be created for the wanted configuration
- SAXException- if parsing fails
- IOException- if I/O error occurs while parsing
- TidyException- if a ParseError is detected and- report_errorsis- true
 
- 
makeTidyParserpublic static org.w3c.tidy.Tidy makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, 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- Parameters:
- node-- Node
- Returns:
- String content of node
 
- 
selectNodeListpublic static NodeList selectNodeList(Document document, String xPathExpression) throws TransformerException Extract NodeList using expression- Parameters:
- document-- Document
- xPathExpression- XPath expression
- Returns:
- NodeList
- Throws:
- TransformerException- when the internally used xpath engine fails
 
- 
putValuesForXPathInListpublic static void putValuesForXPathInList(Document document, String xPathQuery, List<? super String> matchStrings, boolean fragment) throws 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:
- TransformerException- when the internally used xpath engine fails
 
- 
putValuesForXPathInListpublic static void putValuesForXPathInList(Document document, String xPathQuery, List<? super String> matchStrings, boolean fragment, int matchNumber) throws 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:
- TransformerException- when the internally used xpath engine fails
 
- 
putValuesForXPathInListUsingSaxonpublic static void putValuesForXPathInListUsingSaxon(String xmlFile, String xPathQuery, List<? super String> matchStrings, boolean fragment, int matchNumber, String namespaces) throws net.sf.saxon.s9api.SaxonApiException, FactoryConfigurationError - Throws:
- net.sf.saxon.s9api.SaxonApiException
- FactoryConfigurationError
 
- 
namespacesParse
- 
getNamespacespublic static List<String[]> getNamespaces(String xml) throws XMLStreamException, FactoryConfigurationError Compute namespaces for XML- Parameters:
- xml- XML content
- Returns:
- List of Namespaces
- Throws:
- XMLStreamException- on problematic xml
- FactoryConfigurationError- when no xml input factory can be established
 
- 
validateXPathValidate xpathString is a valid XPath expression- Parameters:
- document- XML Document
- xpathString- XPATH String
- Throws:
- TransformerException- if expression fails to evaluate
 
- 
validateXPath2public static void validateXPath2(Document document, String xpathString, String namespaces) throws TransformerException Validate xpathString is a valid XPath expression- Parameters:
- document- XML Document
- xpathString- XPATH String
- namespaces- Space separated set of prefix=namespace
- Throws:
- TransformerException- if expression fails to evaluate
 
- 
computeAssertionResultpublic static void computeAssertionResult(AssertionResult result, Document doc, 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
 
- 
computeAssertionResultUsingSaxonpublic static void computeAssertionResultUsingSaxon(AssertionResult result, String xmlFile, String xPathQuery, String namespaces, Boolean isNegated) throws net.sf.saxon.s9api.SaxonApiException, FactoryConfigurationError - Parameters:
- result- The result of xpath2 assertion
- xmlFile- XML data
- xPathQuery- XPath Query
- namespaces- Space separated set of prefix=namespace
- isNegated- invert result
- Throws:
- net.sf.saxon.s9api.SaxonApiException- when the parser has problems with the given xml or xpath query
- FactoryConfigurationError- when the parser can not be instantiated
 
- 
formatXmlFormats XML- Parameters:
- xml- string to format
- Returns:
- String formatted XML
 
 
-