FileDocCategorySizeDatePackage
DocumentBuilder.javaAPI DocJava SE 5 API10850Fri Aug 26 14:58:22 BST 2005javax.xml.parsers

DocumentBuilder

public abstract class DocumentBuilder extends Object
Defines the API to obtain DOM Document instances from an XML document. Using this class, an application programmer can obtain a {@link Document} from XML.

An instance of this class can be obtained from the {@link DocumentBuilderFactory#newDocumentBuilder()} method. Once an instance of this class is obtained, XML can be parsed from a variety of input sources. These input sources are InputStreams, Files, URLs, and SAX InputSources.

Note that this class reuses several classes from the SAX API. This does not require that the implementor of the underlying DOM implementation use a SAX parser to parse XML document into a Document. It merely requires that the implementation communicate with the application using these existing APIs.

author
Jeff Suttor
version
$Revision: 1.25.14.1.2.1 $, $Date: 2004/06/28 18:23:44 $

Fields Summary
Constructors Summary
protected DocumentBuilder()
Protected constructor

    
Methods Summary
public abstract org.w3c.dom.DOMImplementationgetDOMImplementation()
Obtain an instance of a {@link DOMImplementation} object.

return
A new instance of a DOMImplementation.

public javax.xml.validation.SchemagetSchema()

Get a reference to the the {@link Schema} being used by the XML processor.

If no schema is being used, null is returned.

return
{@link Schema} being used or null if none in use
throws
UnsupportedOperationException For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
since
1.5

        throw new UnsupportedOperationException(
            "This parser does not support specification \""
            + this.getClass().getPackage().getSpecificationTitle()
            + "\" version \""
            + this.getClass().getPackage().getSpecificationVersion()
            + "\""
            );
    
public abstract booleanisNamespaceAware()
Indicates whether or not this parser is configured to understand namespaces.

return
true if this parser is configured to understand namespaces; false otherwise.

public abstract booleanisValidating()
Indicates whether or not this parser is configured to validate XML documents.

return
true if this parser is configured to validate XML documents; false otherwise.

public booleanisXIncludeAware()

Get the XInclude processing mode for this parser.

return
the return value of the {@link DocumentBuilderFactory#isXIncludeAware()} when this parser was created from factory.
throws
UnsupportedOperationException For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
since
1.5
see
DocumentBuilderFactory#setXIncludeAware(boolean)

        throw new UnsupportedOperationException(
            "This parser does not support specification \""
            + this.getClass().getPackage().getSpecificationTitle()
            + "\" version \""
            + this.getClass().getPackage().getSpecificationVersion()
            + "\""
            );
    
public abstract org.w3c.dom.DocumentnewDocument()
Obtain a new instance of a DOM {@link Document} object to build a DOM tree with.

return
A new instance of a DOM Document object.

public org.w3c.dom.Documentparse(java.io.InputStream is)
Parse the content of the given InputStream as an XML document and return a new DOM {@link Document} object. An IllegalArgumentException is thrown if the InputStream is null.

param
is InputStream containing the content to be parsed.
return
Document result of parsing the InputStream
exception
IOException If any IO errors occur.
exception
SAXException If any parse errors occur.
see
org.xml.sax.DocumentHandler

        if (is == null) {
            throw new IllegalArgumentException("InputStream cannot be null");
        }
        
        InputSource in = new InputSource(is);
        return parse(in);
    
public org.w3c.dom.Documentparse(java.io.InputStream is, java.lang.String systemId)
Parse the content of the given InputStream as an XML document and return a new DOM {@link Document} object. An IllegalArgumentException is thrown if the InputStream is null.

param
is InputStream containing the content to be parsed.
param
systemId Provide a base for resolving relative URIs.
return
A new DOM Document object.
exception
IOException If any IO errors occur.
exception
SAXException If any parse errors occur.
see
org.xml.sax.DocumentHandler

        if (is == null) {
            throw new IllegalArgumentException("InputStream cannot be null");
        }
        
        InputSource in = new InputSource(is);
        in.setSystemId(systemId);
        return parse(in);
    
public org.w3c.dom.Documentparse(java.lang.String uri)
Parse the content of the given URI as an XML document and return a new DOM {@link Document} object. An IllegalArgumentException is thrown if the URI is null null.

param
uri The location of the content to be parsed.
return
A new DOM Document object.
exception
IOException If any IO errors occur.
exception
SAXException If any parse errors occur.
see
org.xml.sax.DocumentHandler

        if (uri == null) {
            throw new IllegalArgumentException("URI cannot be null");
        }
        
        InputSource in = new InputSource(uri);
        return parse(in);
    
public org.w3c.dom.Documentparse(java.io.File f)
Parse the content of the given file as an XML document and return a new DOM {@link Document} object. An IllegalArgumentException is thrown if the File is null null.

param
f The file containing the XML to parse.
exception
IOException If any IO errors occur.
exception
SAXException If any parse errors occur.
see
org.xml.sax.DocumentHandler
return
A new DOM Document object.

        if (f == null) {
            throw new IllegalArgumentException("File cannot be null");
        }

        String uri = "file:" + f.getAbsolutePath();
        if (File.separatorChar == '\\") {
            uri = uri.replace('\\", '/");
        }
        InputSource in = new InputSource(uri);
        return parse(in);
    
public abstract org.w3c.dom.Documentparse(org.xml.sax.InputSource is)
Parse the content of the given input source as an XML document and return a new DOM {@link Document} object. An IllegalArgumentException is thrown if the InputSource is null null.

param
is InputSource containing the content to be parsed.
exception
IOException If any IO errors occur.
exception
SAXException If any parse errors occur.
see
org.xml.sax.DocumentHandler
return
A new DOM Document object.

public voidreset()

Reset this DocumentBuilder to its original configuration.

DocumentBuilder is reset to the same state as when it was created with {@link DocumentBuilderFactory#newDocumentBuilder()}. reset() is designed to allow the reuse of existing DocumentBuilders thus saving resources associated with the creation of new DocumentBuilders.

The reset DocumentBuilder is not guaranteed to have the same {@link EntityResolver} or {@link ErrorHandler} Objects, e.g. {@link Object#equals(Object obj)}. It is guaranteed to have a functionally equal EntityResolver and ErrorHandler.

since
1.5

	
		// implementors should override this method
		throw new UnsupportedOperationException(
			"This DocumentBuilder, \"" + this.getClass().getName() + "\", does not support the reset functionality."
			+ "  Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\""
			+ " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\""
			);
	
public abstract voidsetEntityResolver(org.xml.sax.EntityResolver er)
Specify the {@link EntityResolver} to be used to resolve entities present in the XML document to be parsed. Setting this to null will result in the underlying implementation using it's own default implementation and behavior.

param
er The EntityResolver to be used to resolve entities present in the XML document to be parsed.

public abstract voidsetErrorHandler(org.xml.sax.ErrorHandler eh)
Specify the {@link ErrorHandler} to be used by the parser. Setting this to null will result in the underlying implementation using it's own default implementation and behavior.

param
eh The ErrorHandler to be used by the parser.