Class DOMBuilder

java.lang.Object
org.jdom2.input.DOMBuilder

public class DOMBuilder extends Object
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(....);
 
Author:
Brett McLaughlin, Jason Hunter, Philip Nelson, Kevin Regan, Yusuf Goolamabbas, Dan Schaffer, Bradley S. Huffman
  • Constructor Details

    • DOMBuilder

      public DOMBuilder()
      This creates a new DOMBuilder instance using the DefaultJDOMFactory to build the JDOM content.
  • Method Details

    • setFactory

      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 to use
    • getFactory

      public JDOMFactory getFactory()
      Returns the current JDOMFactory in use.
      Returns:
      the factory in use
    • build

      public Document build(Document domDocument)
      This will build a JDOM tree from an existing DOM tree.
      Parameters:
      domDocument - org.w3c.dom.Document object
      Returns:
      Document - JDOM document object.
    • build

      public Element build(Element domElement)
      This will build a JDOM Element from an existing DOM Element
      Parameters:
      domElement - org.w3c.dom.Element object
      Returns:
      Element - JDOM Element object
    • build

      public CDATA build(CDATASection cdata)
      This will build a JDOM CDATA from an existing DOM CDATASection
      Parameters:
      cdata - org.w3c.dom.CDATASection object
      Returns:
      CDATA - JDOM CDATA object
      Since:
      JDOM2
    • build

      public Text build(Text text)
      This will build a JDOM Text from an existing DOM Text
      Parameters:
      text - org.w3c.dom.Text object
      Returns:
      Text - JDOM Text object
      Since:
      JDOM2
    • build

      public Comment build(Comment comment)
      This will build a JDOM Comment from an existing DOM Comment
      Parameters:
      comment - org.w3c.dom.Comment object
      Returns:
      Comment - JDOM Comment object
      Since:
      JDOM2
    • build

      This will build a JDOM ProcessingInstruction from an existing DOM ProcessingInstruction
      Parameters:
      pi - org.w3c.dom.ProcessingInstruction object
      Returns:
      ProcessingInstruction - JDOM ProcessingInstruction object
      Since:
      JDOM2
    • build

      public EntityRef build(EntityReference er)
      This will build a JDOM EntityRef from an existing DOM EntityReference
      Parameters:
      er - org.w3c.dom.EntityReference object
      Returns:
      EnityRef - JDOM EntityRef object
      Since:
      JDOM2
    • build

      public DocType build(DocumentType doctype)
      This will build a JDOM Element from an existing DOM Element
      Parameters:
      doctype - org.w3c.dom.Element object
      Returns:
      Element - JDOM Element object
      Since:
      JDOM2