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 Summary
Modifier and TypeMethodDescriptionstatic void
computeAssertionResult
(AssertionResult result, Document doc, String xPathExpression, boolean isNegated) Fills resultstatic final String
Formats XMLstatic Document
makeDocument
(InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXml, boolean downloadDTDs) Utility function to get new Documentstatic 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) Utility function to get new Documentstatic DocumentBuilder
makeDocumentBuilder
(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs) Create a DocumentBuilder using the makeDocumentFactory func.static Tidy
makeTidyParser
(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter) Create a Tidy parser with the specified settings.static void
putValuesForXPathInList
(Document document, String xPathQuery, List<String> matchStrings, boolean fragment) Put in matchStrings results of evaluationstatic NodeList
selectNodeList
(Document document, String xPathExpression) Extract NodeList using expressionstatic void
validateXPath
(Document document, String xpathString) Validate xpathString is a valid XPath expression
-
Method Details
-
makeDocumentBuilder
public 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
- ifDocumentBuilder
can not be created for the wanted configuration
-
makeDocument
public static Document makeDocument(InputStream stream, boolean validate, boolean whitespace, boolean namespace, boolean tolerant, boolean quiet, boolean showWarnings, boolean report_errors, boolean isXml, boolean downloadDTDs) throws ParserConfigurationException, SAXException, IOException, TidyException Utility function to get new Document- Parameters:
stream
- - Document Input streamvalidate
- - Validate Document (not Tidy)whitespace
- - Element Whitespace (not Tidy)namespace
- - Is Namespace aware. (not Tidy)tolerant
- - Is tolerant - i.e. use the Tidy parserquiet
- - set Tidy quietshowWarnings
- - set Tidy warningsreport_errors
- - throw TidyException if Tidy detects an errorisXml
- - is document already XML (Tidy only)downloadDTDs
- - if true, try to download external DTDs- Returns:
- document
- Throws:
ParserConfigurationException
- when noDocumentBuilder
can be constructed for the wanted configurationSAXException
- if parsing failsIOException
- if an I/O error occurs while parsingTidyException
- if a ParseError is detected andreport_errors
istrue
-
makeDocument
public 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 streamvalidate
- - Validate Document (not Tidy)whitespace
- - Element Whitespace (not Tidy)namespace
- - Is Namespace aware. (not Tidy)tolerant
- - Is tolerant - i.e. use the Tidy parserquiet
- - set Tidy quietshowWarnings
- - set Tidy warningsreport_errors
- - throw TidyException if Tidy detects an errorisXml
- - is document already XML (Tidy only)downloadDTDs
- - if true, try to download external DTDstidyOut
- OutputStream for Tidy pretty-printing- Returns:
- document
- Throws:
ParserConfigurationException
- ifDocumentBuilder
can not be created for the wanted configurationSAXException
- if parsing failsIOException
- if I/O error occurs while parsingTidyException
- if a ParseError is detected andreport_errors
istrue
-
makeTidyParser
public static 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
-
selectNodeList
public 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
-
putValuesForXPathInList
public static void putValuesForXPathInList(Document document, String xPathQuery, List<String> matchStrings, boolean fragment) throws TransformerException Put in matchStrings results of evaluation- Parameters:
document
- XML documentxPathQuery
- XPath QuerymatchStrings
- List of strings that will be filledfragment
- return fragment- Throws:
TransformerException
- when the internally used xpath engine fails
-
validateXPath
Validate xpathString is a valid XPath expression- Parameters:
document
- XML DocumentxpathString
- XPATH String- Throws:
TransformerException
- if expression fails to evaluate
-
computeAssertionResult
public static void computeAssertionResult(AssertionResult result, Document doc, String xPathExpression, boolean isNegated) Fills result- Parameters:
result
-AssertionResult
doc
- XML DocumentxPathExpression
- XPath expressionisNegated
- flag whether a non-match should be considered a success
-
formatXml
Formats XML- Parameters:
xml
- string to format- Returns:
- String formatted XML
-