public class W3CDom extends Object
Document to a org.w3c.dom.Document,
for integration with toolsets that use the W3C DOM.| Modifier and Type | Class and Description |
|---|---|
protected static class |
W3CDom.W3CBuilder
Implements the conversion by walking the input.
|
| Modifier and Type | Field and Description |
|---|---|
protected DocumentBuilderFactory |
factory |
static String |
SourceProperty
For W3C Documents created by this class, this property is set on each node to link back to the original jsoup node.
|
static String |
XPathFactoryProperty
To get support for XPath versions > 1, set this property to the classname of an alternate XPathFactory
implementation.
|
| Constructor and Description |
|---|
W3CDom() |
| Modifier and Type | Method and Description |
|---|---|
String |
asString(Document doc)
Serialize a W3C document to a String.
|
static String |
asString(Document doc,
Map<String,String> properties)
Serialize a W3C document to a String.
|
Node |
contextNode(Document wDoc)
For a Document created by
fromJsoup(org.jsoup.nodes.Element), retrieves the W3C context node. |
static Document |
convert(Document in)
Converts a jsoup DOM to a W3C DOM.
|
void |
convert(Document in,
Document out)
Converts a jsoup document into the provided W3C Document.
|
void |
convert(Element in,
Document out)
Converts a jsoup element into the provided W3C Document.
|
Document |
fromJsoup(Document in)
Convert a jsoup Document to a W3C Document.
|
Document |
fromJsoup(Element in)
Convert a jsoup DOM to a W3C Document.
|
boolean |
namespaceAware()
Returns if this W3C DOM is namespace aware.
|
W3CDom |
namespaceAware(boolean namespaceAware)
Update the namespace aware setting.
|
static HashMap<String,String> |
OutputHtml()
Canned default for HTML output.
|
static HashMap<String,String> |
OutputXml()
Canned default for XML output.
|
NodeList |
selectXpath(String xpath,
Document doc)
Evaluate an XPath query against the supplied document, and return the results.
|
NodeList |
selectXpath(String xpath,
Node contextNode)
Evaluate an XPath query against the supplied context node, and return the results.
|
<T extends Node> |
sourceNodes(NodeList nodeList,
Class<T> nodeType)
Retrieves the original jsoup DOM nodes from a nodelist created by this convertor.
|
public static final String SourceProperty
public static final String XPathFactoryProperty
net.sf.saxon.xpath.XPathFactoryImpl).protected DocumentBuilderFactory factory
public boolean namespaceAware()
true, but is disabled for simplicity
when using XPath selectors in Element.selectXpath(String).public W3CDom namespaceAware(boolean namespaceAware)
namespaceAware - the updated settingpublic static Document convert(Document in)
in - jsoup Documentpublic static String asString(Document doc, @Nullable Map<String,String> properties)
null), the output will be auto-detected based on the content of the
document.doc - Documentproperties - (optional/nullable) the output properties to use. See Transformer.setOutputProperties(Properties) and OutputKeysOutputHtml(),
OutputXml(),
OutputKeys.ENCODING,
OutputKeys.OMIT_XML_DECLARATION,
OutputKeys.STANDALONE,
OutputKeys.STANDALONE,
OutputKeys.DOCTYPE_PUBLIC,
OutputKeys.CDATA_SECTION_ELEMENTS,
OutputKeys.INDENT,
OutputKeys.MEDIA_TYPEpublic Document fromJsoup(Document in)
SourceProperty (but after conversion, changes on one side will not
flow to the other).in - jsoup docpublic Document fromJsoup(Element in)
SourceProperty (but after conversion, changes on one side will not
flow to the other). The input Element is used as a context node, but the whole surrounding jsoup Document is
converted. (If you just want a subtree converted, use convert(org.jsoup.nodes.Element, Document).)in - jsoup element or docsourceNodes(NodeList, Class),
contextNode(Document)public void convert(Document in, Document out)
in - jsoup docout - w3c docfromJsoup(org.jsoup.nodes.Element)public void convert(Element in, Document out)
in - jsoup elementout - w3c docfromJsoup(org.jsoup.nodes.Element)public NodeList selectXpath(String xpath, Document doc)
xpath - an XPath querydoc - the document to evaluate againstpublic NodeList selectXpath(String xpath, Node contextNode)
xpath - an XPath querycontextNode - the context node to evaluate againstpublic <T extends Node> List<T> sourceNodes(NodeList nodeList, Class<T> nodeType)
T - node typenodeList - the W3C nodes to get the original jsoup nodes fromnodeType - the jsoup node type to retrieve (e.g. Element, DataNode, etc)public Node contextNode(Document wDoc)
fromJsoup(org.jsoup.nodes.Element), retrieves the W3C context node.wDoc - Document created by this classpublic String asString(Document doc)
doc - DocumentasString(Document, Map)Copyright © 2009–2022 Jonathan Hedley. All rights reserved.