public abstract class

DocumentBuilder

extends Object
java.lang.Object
   ↳ javax.xml.parsers.DocumentBuilder

Class Overview

Defines a bridge from XML sources (files, stream etc.) to DOM trees. Can be used for easily obtaining a Document for the input. The class itself is abstract. The class DocumentBuilderFactory is able to provide instances (of concrete subclasses known to the system).

Summary

Protected Constructors
DocumentBuilder()
Do-nothing constructor.
Public Methods
abstract DOMImplementation getDOMImplementation()
Queries the DOM implementation this DocumentBuilder is working on.
abstract boolean isNamespaceAware()
Queries whether the DocumentBuilder has namespace support enabled.
abstract boolean isValidating()
Queries whether the DocumentBuilder has validation support enabled.
boolean isXIncludeAware()
Queries whether the DocumentBuilder has XInclude support enabled.
abstract Document newDocument()
Creates a new, empty document, serving as the starting point for a DOM tree.
Document parse(InputStream stream)
Parses a given XML input stream and builds a DOM tree from it.
Document parse(String uri)
Parses an XML input stream from a given URI and builds a DOM tree from it.
Document parse(File file)
Parses a given XML file and builds a DOM tree from it.
abstract Document parse(InputSource source)
Parses an XML input source and builds a DOM tree from it.
Document parse(InputStream stream, String systemId)
Parses a given XML input stream and builds a DOM tree from it.
void reset()
Resets the DocumentBuilder to the same state is was in after its creation.
abstract void setEntityResolver(EntityResolver resolver)
Sets the EntityResolver used for resolving entities encountered during the parse process.
abstract void setErrorHandler(ErrorHandler handler)
Sets the ErrorHandler used for dealing with errors encountered during the parse process.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected DocumentBuilder ()

Since: API Level 1

Do-nothing constructor. Prevents instantiation. To be overridden by concrete subclasses.

Public Methods

public abstract DOMImplementation getDOMImplementation ()

Since: API Level 1

Queries the DOM implementation this DocumentBuilder is working on.

Returns
  • the DOM implementation

public abstract boolean isNamespaceAware ()

Since: API Level 1

Queries whether the DocumentBuilder has namespace support enabled.

Returns
  • true if namespaces are turned on, false otherwise.

public abstract boolean isValidating ()

Since: API Level 1

Queries whether the DocumentBuilder has validation support enabled.

Returns
  • true if validation is turned on, false otherwise.

public boolean isXIncludeAware ()

Since: API Level 1

Queries whether the DocumentBuilder has XInclude support enabled.

Returns
  • true if XInclude support is turned on, false otherwise.
Throws
UnsupportedOperationException if the underlying implementation doesn't support XInclude.

public abstract Document newDocument ()

Since: API Level 1

Creates a new, empty document, serving as the starting point for a DOM tree.

Returns
  • the document.

public Document parse (InputStream stream)

Since: API Level 1

Parses a given XML input stream and builds a DOM tree from it.

Parameters
stream the stream to be parsed.
Returns
  • the document element that represents the root of the DOM tree.
Throws
SAXException if the XML parsing fails.
IOException if an input/output error occurs.

public Document parse (String uri)

Since: API Level 1

Parses an XML input stream from a given URI and builds a DOM tree from it.

Parameters
uri the URI to fetch the XML stream from.
Returns
  • the document element that represents the root of the DOM tree.
Throws
SAXException if the XML parsing fails.
IOException if an input/output error occurs.

public Document parse (File file)

Since: API Level 1

Parses a given XML file and builds a DOM tree from it.

Parameters
file the file to be parsed.
Returns
  • the document element that represents the root of the DOM tree.
Throws
SAXException if the XML parsing fails.
IOException if an input/output error occurs.

public abstract Document parse (InputSource source)

Since: API Level 1

Parses an XML input source and builds a DOM tree from it.

Parameters
source the input source to parse.
Returns
  • the document element that represents the root of the DOM tree.
Throws
SAXException if the XML parsing fails.
IOException if an input/output error occurs.

public Document parse (InputStream stream, String systemId)

Since: API Level 1

Parses a given XML input stream and builds a DOM tree from it.

Parameters
stream the stream to be parsed.
systemId the base for resolving relative URIs.
Returns
  • the document element that represents the root of the DOM tree.
Throws
SAXException if the XML parsing fails.
IOException if an input/output error occurs.

public void reset ()

Since: API Level 1

Resets the DocumentBuilder to the same state is was in after its creation.

public abstract void setEntityResolver (EntityResolver resolver)

Since: API Level 1

Sets the EntityResolver used for resolving entities encountered during the parse process. Passing null results in the DocumentBuilder's own EntityResolver being used.

Parameters
resolver the EntityResolver to use, or null for the built-in one.

public abstract void setErrorHandler (ErrorHandler handler)

Since: API Level 1

Sets the ErrorHandler used for dealing with errors encountered during the parse process. Passing null results in the DocumentBuilder's own ErrorHandler being used.

Parameters
handler the ErrorHandler to use, or null for the built-in one.