public class XPathProcessor extends Object
XPathProcessor is used the create a Document from an URL or InputStream and then
to extract NodeLists, Nodes, Elements, Attributes etc. from this
Document.Elements, Attributes, CDATASections and Texts.| Constructor and Description |
|---|
XPathProcessor(Document document) |
XPathProcessor(InputStream is)
Create a new
XPathProcessor from the given InputStream. |
XPathProcessor(String url)
Create a new
XPathProcessor from the given URL. |
XPathProcessor(URL url)
Create a new
XPathProcessor from the given URL. |
| Modifier and Type | Method and Description |
|---|---|
Node |
addAttribute(Node node,
String name,
String value)
|
Boolean |
getBoolean(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve a Boolean. |
Boolean |
getBoolean(String xpathExpression)
Parses the given
xpathExpression to retrieve a Boolean. |
Document |
getDocument()
|
Element |
getElement(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve an Element. |
Element |
getElement(String xpathExpression)
Parses the given
xpathExpression to retrieve an Element. |
Node |
getNode(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve a Node. |
Node |
getNode(String xpathExpression)
Parses the given
xpathExpression to retrieve a Node. |
NodeList |
getNodes(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve a NodeList. |
NodeList |
getNodes(String xpathExpression)
Parses the given
xpathExpression to retrieve a NodeList. |
Number |
getNumber(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve a Number. |
Number |
getNumber(String xpathExpression)
Parses the given
xpathExpression to retrieve a Number. |
String |
getString(Node node,
String xpathExpression)
Parses the given
xpathExpression to retrieve a String. |
String |
getString(String xpathExpression)
Parses the given
xpathExpression to retrieve a String. |
String |
getXml()
|
String |
getXml(Node node)
Returns the XML-fragment represented by the given
Node. |
String |
getXml(NodeList nodes)
Returns the XML-fragment represented by the given
NodeList. |
void |
getXml(Node node,
OutputStream outputStream)
Writes XML-fragment represented by the given
Node into the given OutputStream. |
void |
getXml(OutputStream outputStream)
|
Attr |
newAttribute(String name,
String value)
Creates a new
Attribute. |
CDATASection |
newCDATA(String tagName)
Creates a new
CDATASection. |
Element |
newElement(String tagName)
Creates a new
Element. |
Text |
newText(String tagName)
Creates a new
Text. |
void |
setNamespace(String prefix,
String namespace)
Sets the namespace and the prefix to use for that namespace.
Example: |
public XPathProcessor(String url) throws IOException
XPathProcessor from the given URL.url - the URLIOException - if an error occurs while reading the XML-document from the URLpublic XPathProcessor(URL url) throws IOException
XPathProcessor from the given URL.url - the URLIOException - if an error occurs while reading the XML-document from the URLpublic XPathProcessor(InputStream is) throws IOException
XPathProcessor from the given InputStream.is - the InputStreamIOException - if an error occurs while reading the XML-document from the InputStreampublic XPathProcessor(Document document) throws IOException
IOExceptionpublic void setNamespace(String prefix, String namespace)
XPathProcessor xpath = ...;
xpath.setNamespace("appng", "http://www.appng.org/schema/platform");
xpath.getNode("/appng:platform//appng:action[@id=\"foo\"]")
prefix - the prefixnamespace - the namespacepublic String getXml(Node node)
Node.node - the Nodepublic void getXml(Node node, OutputStream outputStream)
Node into the given OutputStream.node - the NodeoutputStream - the OutputStreampublic void getXml(OutputStream outputStream)
outputStream - the OutputStream.public String getXml(NodeList nodes)
NodeList.nodes - the NodeListpublic String getString(String xpathExpression)
xpathExpression to retrieve a String.xpathExpression - the xpath-expressionString retrieved from the xpathExpression (may be null), or null if
the expression could not be parsed.public String getString(Node node, String xpathExpression)
xpathExpression to retrieve a String.public Boolean getBoolean(String xpathExpression)
xpathExpression to retrieve a Boolean.xpathExpression - the xpath-expressionBoolean retrieved from the xpathExpression (may be null), or null if
the expression could not be parsed.public Boolean getBoolean(Node node, String xpathExpression)
xpathExpression to retrieve a Boolean.public Number getNumber(String xpathExpression)
xpathExpression to retrieve a Number.xpathExpression - the xpath-expressionNumber retrieved from the xpathExpression (may be null), or null if
the expression could not be parsed.public Number getNumber(Node node, String xpathExpression)
xpathExpression to retrieve a Number.public Node getNode(String xpathExpression)
xpathExpression to retrieve a Node.xpathExpression - the xpath-expressionNode retrieved from the xpathExpression (may be null), or null if the
expression could not be parsed.public Node getNode(Node node, String xpathExpression)
xpathExpression to retrieve a Node.public Element getElement(String xpathExpression)
xpathExpression to retrieve an Element.xpathExpression - the xpath-expressionElement retrieved from the xpathExpression (may be null), or null if
the expression could not be parsed.public Element getElement(Node node, String xpathExpression)
xpathExpression to retrieve an Element.public NodeList getNodes(String xpathExpression)
xpathExpression to retrieve a NodeList.xpathExpression - the xpath-expressionNodeList retrieved from the xpathExpression (may be null), or null if
the expression could not be parsed.public NodeList getNodes(Node node, String xpathExpression)
xpathExpression to retrieve a NodeList.public Attr newAttribute(String name, String value)
Attribute.name - the name of the attributevalue - the value of the attributeAttribute.public Element newElement(String tagName)
Element.tagName - the tag-name for the elementElementpublic CDATASection newCDATA(String tagName)
CDATASection.tagName - the tag-name for the CDATA-sectionCDATASectionpublic Text newText(String tagName)
Text.tagName - the tag-name for the textTextpublic Node addAttribute(Node node, String name, String value)
node - the Node to add the Attribute toname - the name of the Attribute to addvalue - the value of the Attribute to addnode with the added AttributenewAttribute(String, String)Copyright © 2011–2023 aiticon GmbH. All rights reserved.