Top Description Fields Constructors Methods
org.jdom2.input

public Class DOMBuilder

extends Object
Class Inheritance
Static Imports
org.jdom2.JDOMConstants.*

Builds a JDOM Document from a pre-existing DOM org.w3c.dom.Document.

If you are building a document that has Namespace declarations, you should ensure that the Namespaces are correctly recorded in the DOM document before building the JDOM document from the DOM. By default, the native Java DOMBuilderFactory is configured to ignore Namespaces, and thus they are 'lost' in the DOM tree. JDOM expects Namespace-aware documents, so you should ensure that you change the default settings on the DOMBuilderFactory before parsing the DOM document. For example:

    DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
    domfactory.setNamespaceAware(true);
    DocumentBuilder dombuilder = domfac.newDocumentBuilder();
    org.w3c.dom.Document doc = dombuilder.parse(....);
Authors
Brett McLaughlin, Jason Hunter, Philip Nelson, Kevin Regan, Yusuf Goolamabbas, Dan Schaffer, Bradley S. Huffman

Field Summary

Modifier and TypeField and Description
private JDOMFactory
factory

The factory for creating new JDOM objects

Constructor Summary

AccessConstructor and Description
public
DOMBuilder()

This creates a new DOMBuilder instance using the DefaultJDOMFactory to build the JDOM content.

Method Summary

Modifier and TypeMethod and Description
public Document

Returns:

Document - JDOM document object.
build
(Document
org.w3c.dom.Document object
domDocument
)

This will build a JDOM tree from an existing DOM tree.

public Element

Returns:

Element - JDOM Element object
build
(Element
org.w3c.dom.Element object
domElement
)

This will build a JDOM Element from an existing DOM Element

public CDATA

Returns:

CDATA - JDOM CDATA object
build
(CDATASection
org.w3c.dom.CDATASection object
cdata
)

This will build a JDOM CDATA from an existing DOM CDATASection

public Text

Returns:

Text - JDOM Text object
build
(Text
org.w3c.dom.Text object
text
)

This will build a JDOM Text from an existing DOM Text

public Comment

Returns:

Comment - JDOM Comment object
build
(Comment
org.w3c.dom.Comment object
comment
)

This will build a JDOM Comment from an existing DOM Comment

public ProcessingInstruction

Returns:

ProcessingInstruction - JDOM ProcessingInstruction object
build
(ProcessingInstruction
org.w3c.dom.ProcessingInstruction object
pi
)

This will build a JDOM ProcessingInstruction from an existing DOM ProcessingInstruction

public EntityRef

Returns:

EnityRef - JDOM EntityRef object
build
(EntityReference
org.w3c.dom.EntityReference object
er
)

This will build a JDOM EntityRef from an existing DOM EntityReference

public DocType

Returns:

Element - JDOM Element object
build
(DocumentType
org.w3c.dom.Element object
doctype
)

This will build a JDOM Element from an existing DOM Element

private void
buildTree(Node
Code to examine.
node
,
Document
JDOM Document being built.
doc
,
Element
Element that is current parent.
current
,
boolean
boolean indicating whether at root level.
atRoot
)

This takes a DOM Node and builds up a JDOM tree, recursing until the DOM tree is exhausted and the JDOM tree results.

public JDOMFactory

Returns:

the factory in use
getFactory
()

Returns the current org.jdom2.JDOMFactory in use.

public void
setFactory(JDOMFactory
JDOMFactory to use
factory
)

This sets a custom JDOMFactory for the builder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

factoryback to summary
private JDOMFactory factory

The factory for creating new JDOM objects

Constructor Detail

DOMBuilderback to summary
public DOMBuilder()

This creates a new DOMBuilder instance using the DefaultJDOMFactory to build the JDOM content.

Method Detail

buildback to summary
public Document build(Document domDocument)

This will build a JDOM tree from an existing DOM tree.

Parameters
domDocument:Document

org.w3c.dom.Document object

Returns:Document

Document - JDOM document object.

buildback to summary
public Element build(Element domElement)

This will build a JDOM Element from an existing DOM Element

Parameters
domElement:Element

org.w3c.dom.Element object

Returns:Element

Element - JDOM Element object

buildback to summary
public CDATA build(CDATASection cdata)

This will build a JDOM CDATA from an existing DOM CDATASection

Parameters
cdata:CDATASection

org.w3c.dom.CDATASection object

Returns:CDATA

CDATA - JDOM CDATA object

Since
JDOM2
buildback to summary
public Text build(Text text)

This will build a JDOM Text from an existing DOM Text

Parameters
text:Text

org.w3c.dom.Text object

Returns:Text

Text - JDOM Text object

Since
JDOM2
buildback to summary
public Comment build(Comment comment)

This will build a JDOM Comment from an existing DOM Comment

Parameters
comment:Comment

org.w3c.dom.Comment object

Returns:Comment

Comment - JDOM Comment object

Since
JDOM2
buildback to summary
public ProcessingInstruction build(ProcessingInstruction pi)

This will build a JDOM ProcessingInstruction from an existing DOM ProcessingInstruction

Parameters
pi:ProcessingInstruction

org.w3c.dom.ProcessingInstruction object

Returns:ProcessingInstruction

ProcessingInstruction - JDOM ProcessingInstruction object

Since
JDOM2
buildback to summary
public EntityRef build(EntityReference er)

This will build a JDOM EntityRef from an existing DOM EntityReference

Parameters
er:EntityReference

org.w3c.dom.EntityReference object

Returns:EntityRef

EnityRef - JDOM EntityRef object

Since
JDOM2
buildback to summary
public DocType build(DocumentType doctype)

This will build a JDOM Element from an existing DOM Element

Parameters
doctype:DocumentType

org.w3c.dom.Element object

Returns:DocType

Element - JDOM Element object

Since
JDOM2
buildTreeback to summary
private void buildTree(Node node, Document doc, Element current, boolean atRoot)

This takes a DOM Node and builds up a JDOM tree, recursing until the DOM tree is exhausted and the JDOM tree results.

Parameters
node:Node

Code to examine.

doc:Document

JDOM Document being built.

current:Element

Element that is current parent.

atRoot:boolean

boolean indicating whether at root level.

getFactoryback to summary
public JDOMFactory getFactory()

Returns the current org.jdom2.JDOMFactory in use.

Returns:JDOMFactory

the factory in use

setFactoryback to summary
public void setFactory(JDOMFactory factory)

This sets a custom JDOMFactory for the builder. Use this to build the tree with your own subclasses of the JDOM classes.

Parameters
factory:JDOMFactory

JDOMFactory to use