| Method from org.dom4j.DocumentHelper Detail: |
public static Attribute createAttribute(Element owner,
QName qname,
String value) {
return getDocumentFactory().createAttribute(owner, qname, value);
}
|
public static Attribute createAttribute(Element owner,
String name,
String value) {
return getDocumentFactory().createAttribute(owner, name, value);
}
|
public static CDATA createCDATA(String text) {
return DocumentFactory.getInstance().createCDATA(text);
}
|
public static Comment createComment(String text) {
return DocumentFactory.getInstance().createComment(text);
}
|
public static Document createDocument() {
return getDocumentFactory().createDocument();
}
|
public static Document createDocument(Element rootElement) {
return getDocumentFactory().createDocument(rootElement);
}
|
public static Element createElement(QName qname) {
return getDocumentFactory().createElement(qname);
}
|
public static Element createElement(String name) {
return getDocumentFactory().createElement(name);
}
|
public static Entity createEntity(String name,
String text) {
return DocumentFactory.getInstance().createEntity(name, text);
}
|
public static Namespace createNamespace(String prefix,
String uri) {
return DocumentFactory.getInstance().createNamespace(prefix, uri);
}
|
public static Pattern createPattern(String xpathPattern) {
return getDocumentFactory().createPattern(xpathPattern);
}
createPattern parses the given XPath expression to create
an XSLT style Pattern instance which can then be used in an XSLT
processing model.
|
public static ProcessingInstruction createProcessingInstruction(String pi,
String d) {
return getDocumentFactory().createProcessingInstruction(pi, d);
}
|
public static ProcessingInstruction createProcessingInstruction(String pi,
Map data) {
return getDocumentFactory().createProcessingInstruction(pi, data);
}
|
public static QName createQName(String localName) {
return getDocumentFactory().createQName(localName);
}
|
public static QName createQName(String localName,
Namespace namespace) {
return getDocumentFactory().createQName(localName, namespace);
}
|
public static Text createText(String text) {
return DocumentFactory.getInstance().createText(text);
}
|
public static XPath createXPath(String xpathExpression) throws InvalidXPathException {
return getDocumentFactory().createXPath(xpathExpression);
}
createXPath parses an XPath expression and creates a new
XPath XPath instance using the singleton DocumentFactory .
|
public static XPath createXPath(String xpathExpression,
VariableContext context) throws InvalidXPathException {
return getDocumentFactory().createXPath(xpathExpression, context);
}
createXPath parses an XPath expression and creates a new
XPath XPath instance using the singleton DocumentFactory .
|
public static NodeFilter createXPathFilter(String xpathFilterExpression) {
return getDocumentFactory().createXPathFilter(xpathFilterExpression);
}
createXPathFilter parses a NodeFilter from the given XPath
filter expression using the singleton DocumentFactory . XPath
filter expressions occur within XPath expressions such as
self::node()[ filterExpression ]
|
public static Element makeElement(Branch source,
String path) {
StringTokenizer tokens = new StringTokenizer(path, "/");
Element parent;
if (source instanceof Document) {
Document document = (Document) source;
parent = document.getRootElement();
// lets throw a NoSuchElementException
// if we are given an empty path
String name = tokens.nextToken();
if (parent == null) {
parent = document.addElement(name);
}
} else {
parent = (Element) source;
}
Element element = null;
while (tokens.hasMoreTokens()) {
String name = tokens.nextToken();
if (name.indexOf(':") > 0) {
element = parent.element(parent.getQName(name));
} else {
element = parent.element(name);
}
if (element == null) {
element = parent.addElement(name);
}
parent = element;
}
return element;
}
makeElement
a helper method which navigates from the given Document or Element node
to some Element using the path expression, creating any necessary
elements along the way. For example the path a/b/c would
get the first child <a> element, which would be created if it did
not exist, then the next child <b> and so on until finally a
<c> element is returned.
|
public static Document parseText(String text) throws DocumentException {
Document result = null;
SAXReader reader = new SAXReader();
String encoding = getEncoding(text);
InputSource source = new InputSource(new StringReader(text));
source.setEncoding(encoding);
result = reader.read(source);
// if the XML parser doesn't provide a way to retrieve the encoding,
// specify it manually
if (result.getXMLEncoding() == null) {
result.setXMLEncoding(encoding);
}
return result;
}
|
public static List selectNodes(String xpathFilterExpression,
List nodes) {
XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(nodes);
}
selectNodes performs the given XPath expression on the
List of Node instances appending all the results together
into a single list.
|
public static List selectNodes(String xpathFilterExpression,
Node node) {
XPath xpath = createXPath(xpathFilterExpression);
return xpath.selectNodes(node);
}
selectNodes performs the given XPath expression on the
List of Node instances appending all the results together
into a single list.
|
public static void sort(List list,
String xpathExpression) {
XPath xpath = createXPath(xpathExpression);
xpath.sort(list);
}
|
public static void sort(List list,
String expression,
boolean distinct) {
XPath xpath = createXPath(expression);
xpath.sort(list, distinct);
}
sort sorts the given List of Nodes using an XPath
expression as a java.util.Comparator and optionally removing
duplicates.
|