public class DomWrapper extends Object
Default is to not be namespace aware. If set to be namespace aware then the namespace of the root node of the document will be used as the default namespace. Additional namespace mappings can be registered with addnamespace.
| Constructor and Description |
|---|
DomWrapper() |
| Modifier and Type | Method and Description |
|---|---|
void |
addNamespace(String prefix,
String uri)
Register a namespace prefix
|
Node |
findNode(String path)
Find the node addressed by the given path starting from the root of the document
|
Node |
findNode(String path,
Node root)
Find the node addressed by the given path starting from the given root
|
static String |
flatten(Node n)
Return textual serialization of the text content of the node, stripping
out nested elements.
|
static StringBuffer |
flattenTo(Node n,
StringBuffer buffer) |
static String |
getAttribute(Node n,
String name)
Helper function.
|
Document |
getDocument()
Return the document root node.
|
static String |
getRequiredAttribute(Node n,
String name)
Helper function.
|
List<Node> |
listNodes(String path)
Find all nodes matching the given xpath expression, starting
from the root of the document
|
List<Node> |
listNodes(String path,
Node root)
Find all nodes matching the given xpath expression
|
void |
load(InputStream in)
Load and parse a source document.
|
void |
load(String file)
Load and parse a source document.
|
static String |
serialize(Node root)
Return a serialization of element/text contents of this node.
|
static StringBuffer |
serializeChildren(Node root,
StringBuffer buffer) |
static StringBuffer |
serializeTo(Node n,
StringBuffer buffer) |
void |
setNamespaceAware(boolean aware)
Set to true to make the parse and accesses namespace aware.
|
String |
textNode(String path)
Return the text value addressed by the given xpath starting from the document root
|
String |
textNode(String path,
Node root)
Return the text value addressed by the given xpath starting from the given root.
|
String |
textNodes(String path,
Node root)
Return the text value addressed by the given xpath starting from the given root.
|
public void setNamespaceAware(boolean aware)
public void load(String file)
public void load(InputStream in)
public Document getDocument()
public Node findNode(String path)
public Node findNode(String path, Node root)
public List<Node> listNodes(String path)
public List<Node> listNodes(String path, Node root)
path - the expression to search forroot - the root node to search frompublic static String getRequiredAttribute(Node n, String name)
public static String getAttribute(Node n, String name)
public String textNode(String path, Node root)
public String textNodes(String path, Node root)
public String textNode(String path)
public static String serialize(Node root)
public static StringBuffer serializeTo(Node n, StringBuffer buffer)
public static StringBuffer serializeChildren(Node root, StringBuffer buffer)
public static String flatten(Node n)
<emphasis>g</emphasis> general intelligence
would return "g general intelligence"public static StringBuffer flattenTo(Node n, StringBuffer buffer)
Copyright © 2015. All rights reserved.