public class XMLDocument extends Object
Document and provides easy-to-use XPath APIs using a single object.
The XMLDocument class is not thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
XMLDocument.Builder |
| Modifier and Type | Method and Description |
|---|---|
static XMLDocument |
createDocumentFromElement(Element element)
Create a new XML document using the specified
Element as the root node. |
Optional<org.gesis.commons.xml.LocationInfo> |
getLocationInfo(Node node) |
String |
getNamespace()
The namespace of the root element of the document.
|
static XMLDocument.Builder |
newBuilder() |
Node |
selectNode(Node context,
String xPath)
Select a
Node by evaluating a XPath expression using the provided
node as a context the XPath expression will be evaluated in. |
Node |
selectNode(String xPath)
Select a
Node by evaluating a XPath expression using the document
element as the context the XPath will be evaluated in. |
List<Node> |
selectNodes(Node context,
String xPath)
Select a list of
Nodes by evaluating a XPath expression using the provided
node as a context the XPath expression will be evaluated in. |
List<Node> |
selectNodes(String xPath)
Select a list of
Nodes by evaluating a XPath expression using the document
element as the context the XPath will be evaluated in. |
void |
setNamespaceContext(NamespaceContext namespaceContext) |
void |
setRootElement(String xPath,
NamespaceContext nsContext)
Set the root of the document to the element located at the given XPath.
|
public void setNamespaceContext(NamespaceContext namespaceContext)
public void setRootElement(String xPath, NamespaceContext nsContext) throws XPathExpressionException, NoSuchNodeException
xPath - the XPath of the element that should become the root.nsContext - the namespace context of the XPath.XPathExpressionException - if the XPath cannot be evaluated.NoSuchNodeException - if the XPath does not resolve an Element.public static XMLDocument createDocumentFromElement(Element element)
Element as the root node.
The element and all its descendants are adopted into the new document and will be removed from the source document.
element - the root element.public Node selectNode(String xPath) throws XPathExpressionException
Node by evaluating a XPath expression using the document
element as the context the XPath will be evaluated in.xPath - the XPath expression to evaluate.null if no nodes matched.XPathExpressionException - if the XPath expression cannot be compiled.public Node selectNode(Node context, String xPath) throws XPathExpressionException
Node by evaluating a XPath expression using the provided
node as a context the XPath expression will be evaluated in.context - the context the XPath expression will be evaluated in.xPath - the XPath expression to evaluate.null if no nodes matched.XPathExpressionException - if the XPath expression cannot be compiled.public List<Node> selectNodes(Node context, String xPath) throws XPathExpressionException
Nodes by evaluating a XPath expression using the provided
node as a context the XPath expression will be evaluated in.context - the context the XPath expression will be evaluated in.xPath - the XPath expression to evaluate.XPathExpressionException - if the XPath expression cannot be compiled.public List<Node> selectNodes(String xPath) throws XPathExpressionException
Nodes by evaluating a XPath expression using the document
element as the context the XPath will be evaluated in.xPath - the XPath expression to evaluate.XPathExpressionException - if the XPath expression cannot be compiled.public String getNamespace()
public static XMLDocument.Builder newBuilder()
Copyright © 2026 CESSDA ERIC. All rights reserved.