Package org.jsoup.helper
Class W3CDom
java.lang.Object
org.jsoup.helper.W3CDom
public class W3CDom extends Object
Helper class to transform a
Document to a org.w3c.dom.Document,
for integration with toolsets that use the W3C DOM.-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classW3CDom.W3CBuilderImplements the conversion by walking the input. -
Field Summary
Fields Modifier and Type Field Description protected DocumentBuilderFactoryfactorystatic StringSourcePropertyFor W3C Documents created by this class, this property is set on each node to link back to the original jsoup node.static StringXPathFactoryPropertyTo get support for XPath versions > 1, set this property to the classname of an alternate XPathFactory implementation (e.g. -
Constructor Summary
Constructors Constructor Description W3CDom() -
Method Summary
Modifier and Type Method Description StringasString(Document doc)Serialize a W3C document to a String.static StringasString(Document doc, Map<String,String> properties)Serialize a W3C document to a String.static Documentconvert(Document in)Converts a jsoup DOM to a W3C DOM.voidconvert(Document in, Document out)Converts a jsoup document into the provided W3C Document.voidconvert(Element in, Document out)Converts a jsoup element into the provided W3C Document.DocumentfromJsoup(Document in)Convert a jsoup Document to a W3C Document.DocumentfromJsoup(Element in)Convert a jsoup Element to a W3C Document.static HashMap<String,String>OutputHtml()Canned default for HTML output.static HashMap<String,String>OutputXml()Canned default for XML output.NodeListselectXpath(String xpath, Document doc)<T extends Node>
List<T>sourceNodes(NodeList nodeList, Class<T> nodeType)
-
Field Details
-
SourceProperty
For W3C Documents created by this class, this property is set on each node to link back to the original jsoup node.- See Also:
- Constant Field Values
-
XPathFactoryProperty
To get support for XPath versions > 1, set this property to the classname of an alternate XPathFactory implementation (e.g.net.sf.saxon.xpath.XPathFactoryImpl).- See Also:
- Constant Field Values
-
factory
-
-
Constructor Details
-
W3CDom
public W3CDom()
-
-
Method Details
-
convert
Converts a jsoup DOM to a W3C DOM.- Parameters:
in- jsoup Document- Returns:
- W3C Document
-
asString
Serialize a W3C document to a String. Provide Properties to define output settings including if HTML or XML. If you don't provide the properties (null), the output will be auto-detected based on the content of the document.- Parameters:
doc- Documentproperties- (optional/nullable) the output properties to use. SeeTransformer.setOutputProperties(Properties)andOutputKeys- Returns:
- Document as string
- See Also:
OutputHtml(),OutputXml(),OutputKeys.ENCODING,OutputKeys.OMIT_XML_DECLARATION,OutputKeys.STANDALONE,OutputKeys.STANDALONE,OutputKeys.DOCTYPE_PUBLIC,OutputKeys.DOCTYPE_PUBLIC,OutputKeys.CDATA_SECTION_ELEMENTS,OutputKeys.INDENT,OutputKeys.MEDIA_TYPE
-
OutputHtml
Canned default for HTML output. -
OutputXml
Canned default for XML output. -
fromJsoup
Convert a jsoup Document to a W3C Document. The created nodes will link back to the original jsoup nodes in the user propertySourceProperty(but after conversion, changes on one side will not flow to the other).- Parameters:
in- jsoup doc- Returns:
- a W3C DOM Document representing the jsoup Document or Element contents.
-
fromJsoup
Convert a jsoup Element to a W3C Document. The created nodes will link back to the original jsoup nodes in the user propertySourceProperty(but after conversion, changes on one side will not flow to the other).- Parameters:
in- jsoup element or doc- Returns:
- a W3C DOM Document representing the jsoup Document or Element contents.
-
convert
Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document before converting.- Parameters:
in- jsoup docout- w3c doc- See Also:
fromJsoup(org.jsoup.nodes.Element)
-
convert
Converts a jsoup element into the provided W3C Document. If required, you can set options on the output document before converting.- Parameters:
in- jsoup elementout- w3c doc- See Also:
fromJsoup(org.jsoup.nodes.Element)
-
selectXpath
-
sourceNodes
-
asString
Serialize a W3C document to a String. The output format will be XML or HTML depending on the content of the doc.- Parameters:
doc- Document- Returns:
- Document as string
- See Also:
asString(Document, Map)
-