public class XPathUtil extends Object
Modifier and Type | Method and Description |
---|---|
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
|
static List<String[]> |
getNamespaces(String xml)
Compute namespaces for XML
|
static net.sf.saxon.s9api.Processor |
getProcessor() |
static String |
getValueForNode(Node node) |
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 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,
StringWriter stringWriter)
Create a Tidy parser with the specified settings.
|
static List<String[]> |
namespacesParse(String namespaces) |
static void |
putValuesForXPathInList(Document document,
String xPathQuery,
List<String> matchStrings,
boolean fragment)
Put in matchStrings results of evaluation
|
static void |
putValuesForXPathInList(Document document,
String xPathQuery,
List<String> matchStrings,
boolean fragment,
int matchNumber)
Put in matchStrings results of evaluation
|
static void |
putValuesForXPathInListUsingSaxon(String xmlFile,
String xPathQuery,
List<String> matchStrings,
boolean fragment,
int matchNumber,
String namespaces) |
static NodeList |
selectNodeList(Document document,
String xPathExpression)
Extract NodeList using expression
|
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
|
public static net.sf.saxon.s9api.Processor getProcessor()
public static DocumentBuilder makeDocumentBuilder(boolean validate, boolean whitespace, boolean namespace, boolean downloadDTDs) throws ParserConfigurationException
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 entitiesParserConfigurationException
- if DocumentBuilder
can not be created for the wanted configurationpublic 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
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 warningsreportErrors
- - throw TidyException if Tidy detects an errorisXml
- - is document already XML (Tidy only)downloadDTDs
- - if true, try to download external DTDsParserConfigurationException
- when no DocumentBuilder
can be constructed for the wanted configurationSAXException
- if parsing failsIOException
- if an I/O error occurs while parsingTidyException
- if a ParseError is detected and report_errors
is true
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
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-printingParserConfigurationException
- if DocumentBuilder
can not be created for the wanted configurationSAXException
- if parsing failsIOException
- if I/O error occurs while parsingTidyException
- if a ParseError is detected and report_errors
is true
public static org.w3c.tidy.Tidy makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter)
quiet
- - set the Tidy quiet flag?showWarnings
- - show Tidy warnings?isXml
- - treat the content as XML?stringWriter
- - if non-null, use this for Tidy errorOutputpublic static String getValueForNode(Node node)
node
- Node
public static NodeList selectNodeList(Document document, String xPathExpression) throws TransformerException
document
- Document
xPathExpression
- XPath expressionNodeList
TransformerException
- when the internally used xpath engine failspublic static void putValuesForXPathInList(Document document, String xPathQuery, List<String> matchStrings, boolean fragment) throws TransformerException
document
- XML documentxPathQuery
- XPath QuerymatchStrings
- List of strings that will be filledfragment
- return fragmentTransformerException
- when the internally used xpath engine failspublic static void putValuesForXPathInList(Document document, String xPathQuery, List<String> matchStrings, boolean fragment, int matchNumber) throws TransformerException
document
- XML documentxPathQuery
- XPath QuerymatchStrings
- List of strings that will be filledfragment
- return fragmentmatchNumber
- match numberTransformerException
- when the internally used xpath engine failspublic static void putValuesForXPathInListUsingSaxon(String xmlFile, String xPathQuery, List<String> matchStrings, boolean fragment, int matchNumber, String namespaces) throws net.sf.saxon.s9api.SaxonApiException, FactoryConfigurationError
net.sf.saxon.s9api.SaxonApiException
FactoryConfigurationError
public static List<String[]> getNamespaces(String xml) throws XMLStreamException, FactoryConfigurationError
xml
- XML contentXMLStreamException
- on problematic xmlFactoryConfigurationError
- when no xml input factory can be establishedpublic static void validateXPath(Document document, String xpathString) throws TransformerException
document
- XML DocumentxpathString
- XPATH StringTransformerException
- if expression fails to evaluatepublic static void validateXPath2(Document document, String xpathString, String namespaces) throws TransformerException
document
- XML DocumentxpathString
- XPATH Stringnamespaces
- Space separated set of prefix=namespaceTransformerException
- if expression fails to evaluatepublic static void computeAssertionResult(AssertionResult result, Document doc, String xPathExpression, boolean isNegated)
result
- AssertionResult
doc
- XML DocumentxPathExpression
- XPath expressionisNegated
- flag whether a non-match should be considered a successpublic static void computeAssertionResultUsingSaxon(AssertionResult result, String xmlFile, String xPathQuery, String namespaces, Boolean isNegated) throws net.sf.saxon.s9api.SaxonApiException, FactoryConfigurationError
result
- The result of xpath2 assertionxmlFile
- XML dataxPathQuery
- XPath Querynamespaces
- Space separated set of prefix=namespaceisNegated
- invert resultnet.sf.saxon.s9api.SaxonApiException
- when the parser has problems with the given xml or xpath queryFactoryConfigurationError
- when the parser can not be instantiatedCopyright © 1998-2019 Apache Software Foundation. All Rights Reserved.