Package org.apache.jmeter.util
Class XPathUtil
-
- All Implemented Interfaces:
public class XPathUtil
This class provides a few utility methods for dealing with XML/XPath.
-
-
Method Summary
Modifier and Type Method Description static Processor
getProcessor()
static DocumentBuilder
makeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs)
Create a DocumentBuilder using the makeDocumentFactory func. static Document
makeDocument(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 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 Document static Tidy
makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter)
Create a Tidy parser with the specified settings. static String
getValueForNode(Node node)
static NodeList
selectNodeList(Document document, String xPathExpression)
Extract NodeList using expression static void
putValuesForXPathInList(Document document, String xPathQuery, List<in String> matchStrings, boolean fragment)
Put in matchStrings results of evaluation static void
putValuesForXPathInList(Document document, String xPathQuery, List<in String> matchStrings, boolean fragment, int matchNumber)
Put in matchStrings results of evaluation static void
putValuesForXPathInListUsingSaxon(String xmlFile, String xPathQuery, List<in String> matchStrings, boolean fragment, int matchNumber, String namespaces)
static List<Array<String>>
namespacesParse(String namespaces)
static List<Array<String>>
getNamespaces(String xml)
Compute namespaces for XML static void
validateXPath(Document document, String xpathString)
Validate xpathString is a valid XPath expression static void
validateXPath2(Document document, String xpathString, String namespaces)
Validate xpathString is a valid XPath expression static void
computeAssertionResult(AssertionResult result, Document doc, String xPathExpression, boolean isNegated)
Fills result static void
computeAssertionResultUsingSaxon(AssertionResult result, String xmlFile, String xPathQuery, String namespaces, Boolean isNegated)
* static String
formatXml(String xml)
Formats XML -
-
Method Detail
-
getProcessor
static Processor getProcessor()
-
makeDocumentBuilder
static DocumentBuilder makeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs)
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
-
makeDocument
static Document makeDocument(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
- Parameters:
stream
- - Document Input streamvalidate
- - Validate Document (not Tidy)whitespace
- - Element Whitespace (not Tidy)namespace
- - Is Namespace aware.tolerant
- - Is tolerant - i.e.quiet
- - set Tidy quietshowWarnings
- - set Tidy warningsreportErrors
- - throw TidyException if Tidy detects an errorisXml
- - is document already XML (Tidy only)downloadDTDs
- - if true, try to download external DTDs- Returns:
document
-
makeDocument
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)
Utility function to get new Document
- Parameters:
stream
- - Document Input streamvalidate
- - Validate Document (not Tidy)whitespace
- - Element Whitespace (not Tidy)namespace
- - Is Namespace aware.tolerant
- - Is tolerant - i.e.quiet
- - 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
-
makeTidyParser
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
-
getValueForNode
static String getValueForNode(Node node)
- Parameters:
node
- Node- Returns:
String content of node
-
selectNodeList
static NodeList selectNodeList(Document document, String xPathExpression)
Extract NodeList using expression
-
putValuesForXPathInList
static void putValuesForXPathInList(Document document, String xPathQuery, List<in String> matchStrings, boolean fragment)
Put in matchStrings results of evaluation
- Parameters:
document
- XML documentxPathQuery
- XPath QuerymatchStrings
- List of strings that will be filledfragment
- return fragment
-
putValuesForXPathInList
static void putValuesForXPathInList(Document document, String xPathQuery, List<in String> matchStrings, boolean fragment, int matchNumber)
Put in matchStrings results of evaluation
- Parameters:
document
- XML documentxPathQuery
- XPath QuerymatchStrings
- List of strings that will be filledfragment
- return fragmentmatchNumber
- match number
-
putValuesForXPathInListUsingSaxon
static void putValuesForXPathInListUsingSaxon(String xmlFile, String xPathQuery, List<in String> matchStrings, boolean fragment, int matchNumber, String namespaces)
-
namespacesParse
static List<Array<String>> namespacesParse(String namespaces)
-
getNamespaces
static List<Array<String>> getNamespaces(String xml)
Compute namespaces for XML
- Parameters:
xml
- XML content- Returns:
List of Namespaces
-
validateXPath
static void validateXPath(Document document, String xpathString)
Validate xpathString is a valid XPath expression
- Parameters:
document
- XML DocumentxpathString
- XPATH String
-
validateXPath2
static void validateXPath2(Document document, String xpathString, String namespaces)
Validate xpathString is a valid XPath expression
- Parameters:
document
- XML DocumentxpathString
- XPATH Stringnamespaces
- Space separated set of prefix=namespace
-
computeAssertionResult
static void computeAssertionResult(AssertionResult result, Document doc, String xPathExpression, boolean isNegated)
Fills result
- Parameters:
result
- AssertionResultdoc
- XML DocumentxPathExpression
- XPath expressionisNegated
- flag whether a non-match should be considered a success
-
computeAssertionResultUsingSaxon
static void computeAssertionResultUsingSaxon(AssertionResult result, String xmlFile, String xPathQuery, String namespaces, Boolean isNegated)
*
- Parameters:
result
- The result of xpath2 assertionxmlFile
- XML dataxPathQuery
- XPath Querynamespaces
- Space separated set of prefix=namespaceisNegated
- invert result
-
-
-
-