public class XPathProcessor extends Object
XPathProcessor
is used the create a Document
from an URL
or InputStream
and then
to extract NodeList
s, Node
s, Element
s, Attr
ibutes etc. from this Document
.Element
s, Attr
ibutes, CDATASection
s and Text
s.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
Attr ibute. |
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 URL
public XPathProcessor(InputStream is) throws IOException
XPathProcessor
from the given InputStream
.is
- the InputStream
IOException
- if an error occurs while reading the XML-document from the InputStream
public XPathProcessor(Document document) throws IOException
IOException
public 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 Node
public void getXml(Node node, OutputStream outputStream)
Node
into the given OutputStream
.node
- the Node
outputStream
- the OutputStream
public void getXml(OutputStream outputStream)
outputStream
- the OutputStream
.public String getXml(NodeList nodes)
NodeList
.nodes
- the NodeList
public 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)
Attr
ibute.name
- the name of the attributevalue
- the value of the attributeAttr
ibute.public Element newElement(String tagName)
Element
.tagName
- the tag-name for the elementElement
public CDATASection newCDATA(String tagName)
CDATASection
.tagName
- the tag-name for the CDATA-sectionCDATASection
public Text newText(String tagName)
Text
.tagName
- the tag-name for the textText
public Node addAttribute(Node node, String name, String value)
node
- the Node to add the Attr
ibute toname
- the name of the Attr
ibute to addvalue
- the value of the Attr
ibute to addnode
with the added Attr
ibutenewAttribute(String, String)
Copyright © 2011–2019 aiticon GmbH. All rights reserved.