| Java Doc By Examples | |
| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjavax.xml.parsers.DocumentBuilderFactorypublic abstract class DocumentBuilderFactoryextends ObjectConstructor Summary | |
Method Summary | |
abstract Object |
|
abstract boolean |
|
Schema | |
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
abstract DocumentBuilder |
|
static DocumentBuilderFactory |
|
abstract void |
|
void |
|
void |
|
abstract void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public abstract Object getAttribute(String name) throws IllegalArgumentException
Allows the user to retrieve specific attributes on the underlying implementation.
- Parameters:
name- The name of the attribute.
- Returns:
- value The value of the attribute.
- Throws:
IllegalArgumentException- thrown if the underlying implementation doesn't recognize the attribute.
1: import javax.xml.XMLConstants; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: void setAttr(boolean setSrc) { 6: DocumentBuilderFactory docBFactory = DocumentBuilderFactory.newInstance(); 7: Schema sch = createSchema(); 8: docBFactory.setSchema(sch); 9: docBFactory.setNamespaceAware(true);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory 7: { 8: ... 9: 10: private DocumentBuilderFactory delegate; 11: 12: ... 13: { 14: return delegate.getAttribute(name);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: { 14: return _WrappedFactory.getAttribute(name);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: } 13: return core.getAttribute(name);
public abstract boolean getFeature(String name) throws ParserConfigurationException
Get the state of the named feature. Feature names are fully qualifiedURIs. Implementations may define their own features. AnParserConfigurationExceptionis thrown if thisDocumentBuilderFactoryor theDocumentBuilders it creates cannot support the feature. It is possible for anDocumentBuilderFactoryto expose a feature value but be unable to change its state.
- Parameters:
name- Feature name.
- Returns:
- State of the named feature.
- Throws:
ParserConfigurationException- if thisDocumentBuilderFactoryor theDocumentBuilders it creates cannot support this feature.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory 7: { 8: ... 9: 10: private DocumentBuilderFactory delegate; 11: 12: ... 13: { 14: return delegate.getFeature(name);
1: 2: DocumentBuilderFactory dbf = null; 3: 4: ... 5: try{ 6: dbf = DocumentBuilderFactory.newInstance(); 7: DocumentBuilder parser = dbf.newDocumentBuilder(); 8: ... 9: try{ 10: dbf = DocumentBuilderFactory.newInstance(); 11: dbf.setNamespaceAware(true); 12: ... 13: dbf = DocumentBuilderFactory.newInstance(); 14: assertTrue("Default value for secureProcessing feature should be true",dbf.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
public Schema getSchema()
Gets theSchemaobject specified through thesetSchema(Schema schema)method.
- Returns:
- the
Schemaobject that was last set through thesetSchema(Schema)method, or null if the method was not invoked since aSAXParserFactoryis created.
- Throws:
UnsupportedOperationException- For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
- Since:
- 1.5
public boolean isCoalescing()
Indicates whether or not the factory is configured to produce parsers which converts CDATA nodes to Text nodes and appends it to the adjacent (if any) Text node.
- Returns:
- true if the factory is configured to produce parsers which converts CDATA nodes to Text nodes and appends it to the adjacent (if any) Text node; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public boolean isCoalescing() 14: { return _WrappedFactory.isCoalescing(); }
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isCoalescing() { 13: return core.isCoalescing();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: builder.setIgnoreComments(dbf.isIgnoringComments()); 14: builder.setPutCDATAIntoText(dbf.isCoalescing());
public boolean isExpandEntityReferences()
Indicates whether or not the factory is configured to produce parsers which expand entity reference nodes.
- Returns:
- true if the factory is configured to produce parsers which expand entity reference nodes; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public boolean isExpandEntityReference() 14: { return _WrappedFactory.isExpandEntityReferences(); }
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isExpandEntityReference() { 13: return core.isExpandEntityReferences();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: builder.setIgnoreWhitespace(dbf.isIgnoringElementContentWhitespace()); 14: builder.setExpandEntityReferences(dbf.isExpandEntityReferences());
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: _isCoalescing = factory.isCoalescing(); 10: setExpandEntities(factory.isExpandEntityReferences()); 11: setSkipComments(factory.isIgnoringComments());
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: _isCoalescing = factory.isCoalescing(); 10: setExpandEntities(factory.isExpandEntityReferences()); 11: setSkipComments(factory.isIgnoringComments());
public boolean isIgnoringComments()
Indicates whether or not the factory is configured to produce parsers which ignores comments.
- Returns:
- true if the factory is configured to produce parsers which ignores comments; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public boolean isIgnoringComments() 14: { return _WrappedFactory.isIgnoringComments(); }
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isIgnoringComments() { 13: return core.isIgnoringComments();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: builder.setExpandEntityReferences(dbf.isExpandEntityReferences()); 14: builder.setIgnoreComments(dbf.isIgnoringComments());
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: setExpandEntities(factory.isExpandEntityReferences()); 10: setSkipComments(factory.isIgnoringComments()); 11: setSkipWhitespace(factory.isIgnoringElementContentWhitespace());
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: setExpandEntities(factory.isExpandEntityReferences()); 10: setSkipComments(factory.isIgnoringComments()); 11: setSkipWhitespace(factory.isIgnoringElementContentWhitespace());
public boolean isIgnoringElementContentWhitespace()
Indicates whether or not the factory is configured to produce parsers which ignore ignorable whitespace in element content.
- Returns:
- true if the factory is configured to produce parsers which ignore ignorable whitespace in element content; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public boolean isIgnoringElementContentWhitespace() 14: { return _WrappedFactory.isIgnoringElementContentWhitespace(); }
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private static DocumentBuilderFactory documentBuilderFactory; 7: 8: ... 9: || documentBuilderFactory.isNamespaceAware() != namespace 10: || documentBuilderFactory.isIgnoringElementContentWhitespace() != whitespace) { 11: documentBuilderFactory = DocumentBuilderFactory.newInstance();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isIgnoringElementContentWhitespace() { 13: return core.isIgnoringElementContentWhitespace();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: 14: builder.setIgnoreWhitespace(dbf.isIgnoringElementContentWhitespace());
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: setSkipComments(factory.isIgnoringComments()); 10: setSkipWhitespace(factory.isIgnoringElementContentWhitespace()); 11: setNamespaceAware(factory.isNamespaceAware());
public boolean isNamespaceAware()
Indicates whether or not the factory is configured to produce parsers which are namespace aware.
- Returns:
- true if the factory is configured to produce parsers which are namespace aware; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public boolean isNamespaceAware() 14: { return _WrappedFactory.isNamespaceAware(); }
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private static DocumentBuilderFactory documentBuilderFactory; 7: 8: ... 9: if (XPathUtil.documentBuilderFactory == null || documentBuilderFactory.isValidating() != validate 10: || documentBuilderFactory.isNamespaceAware() != namespace 11: || documentBuilderFactory.isIgnoringElementContentWhitespace() != whitespace) {
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isNamespaceAware() { 13: return core.isNamespaceAware();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: this.dbf = dbf; 14: namespaceAware = dbf.isNamespaceAware();
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.FileNotFoundException; 4: ... 5: 6: public void setConfig(DocumentBuilderFactory factory) 7: { 8: ... 9: setSkipWhitespace(factory.isIgnoringElementContentWhitespace()); 10: setNamespaceAware(factory.isNamespaceAware()); 11: setNamespacePrefixes(false);
public boolean isValidating()
Indicates whether or not the factory is configured to produce parsers which validate the XML content during parse.
- Returns:
- true if the factory is configured to produce parsers which validate the XML content during parse; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { 7: 8: ... 9: private final DocumentBuilderFactory core; 10: 11: ... 12: public boolean isValidating() { 13: return core.isValidating();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: private DocumentBuilderFactory dbf; 7: 8: ... 9: 10: DocumentBuilderImpl(DocumentBuilderFactory dbf) 11: throws ParserConfigurationException 12: ... 13: try { 14: validating = dbf.isValidating();
public boolean isXIncludeAware()
Get state of XInclude processing.
- Returns:
- current state of XInclude processing
- Throws:
UnsupportedOperationException- For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
- Since:
- 1.5
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
Creates a new instance of aDocumentBuilderusing the currently configured parameters.
- Returns:
- A new instance of a DocumentBuilder.
- Throws:
ParserConfigurationException- if a DocumentBuilder cannot be created which satisfies the configuration requested.
1: public DocumentBuilder getDomParser() throws Exception { 2: DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance(); 3: ... 4: return docBF.newDocumentBuilder(); 5: } 6: }
1: protected void setUp() throws Exception { 2: DocumentBuilderFactory factory = 3: new DocumentBuilderFactoryImpl(); 4: ... 5: DocumentBuilder documentBuilder = 6: factory.newDocumentBuilder(); 7: 8: documentBuilder.setEntityResolver( 9: new StringEntityResolver(""));
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: try { 6: DocumentBuilderFactory factory = 7: ... 8: DocumentBuilderFactory.newInstance(); 9: 10: ... 11: factory.setCoalescing(isCoalescing()); 12: return factory.newDocumentBuilder().parse(stream);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: try { 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: dbf.setNamespaceAware(true); 8: ... 9: return dbf.newDocumentBuilder(); 10: } catch( ParserConfigurationException e ) {
public static DocumentBuilderFactory newInstance()
Obtain a new instance of aDocumentBuilderFactory. This static method creates a new factory instance. This method uses the following ordered lookup procedure to determine theDocumentBuilderFactoryimplementation class to load:Once an application has obtained a reference to a
- Use the
javax.xml.parsers.DocumentBuilderFactorysystem property.- Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard
java.util.Propertiesformat and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any property in jaxp.properties after it has been read for the first time.- Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for a classname in the file
META-INF/services/javax.xml.parsers.DocumentBuilderFactoryin jars available to the runtime.- Platform default
DocumentBuilderFactoryinstance.DocumentBuilderFactoryit can use the factory to configure and obtain parser instances.Tip for Trouble-shooting
Setting thejaxp.debugsystem property will cause this method to print a lot of debug messages to System.err about what it is doing and where it is looking at. If you have problems loadingDocumentBuilders, try:java -Djaxp.debug=1 YourProgram ....
- Returns:
- New instance of a
DocumentBuilderFactory
1: public DOMTest2(String uri) throws Exception { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: factory.setValidating(true); 6: DocumentBuilder builder = factory.newDocumentBuilder(); 7: Document doc = builder.parse(uri);
1: DocumentBuilder parser = 2: DocumentBuilderFactory.newInstance().newDocumentBuilder(); 3: Document document = parser.parse( new InputSource("zooinventory.xml") ); 4: ... 5: Transformer transformer = 6: TransformerFactory.newInstance().newTransformer(); 7: Source source = new DOMSource( document ); 8: Result output = new StreamResult( System.out ); 9: transformer.transform( source, output );
1: public DOMTest6() throws Exception { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: factory.setValidating(true); 6: DocumentBuilder builder = factory.newDocumentBuilder();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: super.setUp(); 6: final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 7: ... 8: final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); 9: document = documentBuilder.newDocument();
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: public StaticXsltView() throws Exception { 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: DocumentBuilder db = dbf.newDocumentBuilder(); 8: this.doc = db.parse(new File("C:\\work\\book\\ticket\\war\\xsl\\in.xml")); 9: logger.warning("Cached XML document");
public abstract void setAttribute(String name, Object value) throws IllegalArgumentException
Allows the user to set specific attributes on the underlying implementation.
- Parameters:
name- The name of the attribute.value- The value of the attribute.
- Throws:
IllegalArgumentException- thrown if the underlying implementation doesn't recognize the attribute.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.File; 4: ... 5: public static void main(String[] args) throws Exception { 6: DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 7: DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); 8: Document document = documentBuilder.parse(new File(args[0])); 9: System.out.println(document.getClass());
1: public void print(String fileName) throws SAXException, IOException { 2: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 3: factory.setValidating(true); 4: factory.setNamespaceAware(true); 5: try {
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: { 6: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 7: documentBuilderFactory.setNamespaceAware(true); 8: documentBuilderFactory.setValidating(false); 9: try
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 7: 8:
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import java.io.File; 4: ... 5: { 6: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 7: LocalFileEntityResolver entityResolver = LocalFileEntityResolver.getInstance(); 8: 9: if (_schemaFileName != null) {
public void setCoalescing(boolean coalescing)
Specifies that the parser produced by this code will convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node. By default the value of this is set tofalse
- Parameters:
coalescing- true if the parser produced will convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node; false otherwise.
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: try { 6: DocumentBuilderFactory factory = 7: ... 8: DocumentBuilderFactory.newInstance(); 9: 10: ... 11: factory.setIgnoringComments(isIgnoringComments()); 12: factory.setCoalescing(isCoalescing());
1: { 2: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 3: 4: DocumentBuilder parser = factory.newDocumentBuilder();
1: 2: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3: 4: ... 5: dbf.setExpandEntityReferences(true); 6: dbf.setCoalescing(true); 7: 8: DocumentBuilder db = null; 9: try {
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: Document doc = null; 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: dbf.setValidating(false); 8: ... 9: dbf.setNamespaceAware(true); 10: dbf.setCoalescing(false); 11: doc = STAXUtils.read(dbf.newDocumentBuilder(), context.getInMessage()
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: private void parseConfiguration(InputStream is) throws Exception { 6: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 7: factory.setIgnoringComments(true); 8: ... 9: factory.setCoalescing(true); 10: factory.setNamespaceAware(false);
public void setExpandEntityReferences(boolean expandEntityRef)
Specifies that the parser produced by this code will expand entity reference nodes. By default the value of this is set totrue
- Parameters:
expandEntityRef- true if the parser produced will expand entity reference nodes; false otherwise.
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: try { 6: DocumentBuilderFactory factory = 7: ... 8: DocumentBuilderFactory.newInstance(); 9: 10: ... 11: isIgnoringElementContentWhitespace()); 12: factory.setExpandEntityReferences(isExpandEntityReferences());
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: if (builder == null) { 6: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 7: factory.setNamespaceAware(false); 8: ... 9: factory.setExpandEntityReferences(false); 10: builder = factory.newDocumentBuilder();
1: 2: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3: 4: ... 5: dbf.setIgnoringElementContentWhitespace(false); 6: dbf.setExpandEntityReferences(true); 7: dbf.setCoalescing(true); 8: 9: DocumentBuilder db = null;
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public void setExpandEntityReference(boolean expandEntityRef) 14: { _WrappedFactory.setExpandEntityReferences(expandEntityRef); }
1: import org.w3c.dom.Document; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.DocumentBuilder; 4: ... 5: 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: DocumentBuilder db = null; 8: ... 9: dbf.setCoalescing(true); 10: dbf.setExpandEntityReferences(true);
public abstract void setFeature(String name, boolean value) throws ParserConfigurationException
Set a feature for thisDocumentBuilderFactoryandDocumentBuilders created by this factory. Feature names are fully qualifiedURIs. Implementations may define their own features. AnParserConfigurationExceptionis thrown if thisDocumentBuilderFactoryor theDocumentBuilders it creates cannot support the feature. It is possible for anDocumentBuilderFactoryto expose a feature value but be unable to change its state. All implementations are required to support theXMLConstants.FEATURE_SECURE_PROCESSINGfeature. When the feature is:
true: the implementation will limit XML processing to conform to implementation limits. Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources. If XML processing is limited for security reasons, it will be reported via a call to the registeredorg.xml.sax.ErrorHandler.fatalError(SAXParseException exception). SeeDocumentBuilder.setErrorHandler(org.xml.sax.ErrorHandler errorHandler).false: the implementation will processing XML according to the XML specifications without regard to possible implementation limits.
- Parameters:
name- Feature name.value- Is feature statetrueorfalse.
- Throws:
ParserConfigurationException- if thisDocumentBuilderFactoryor theDocumentBuilders it creates cannot support this feature.NullPointerException- If thenameparameter is null.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: } 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: ... 8: dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,enableSecureProcessing); 9:
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory 7: { 8: ... 9: 10: private DocumentBuilderFactory delegate; 11: 12: ... 13: { 14: delegate.setFeature(name, value);
1: 2: DocumentBuilderFactory dbf = null; 3: 4: ... 5: try{ 6: dbf = DocumentBuilderFactory.newInstance(); 7: DocumentBuilder parser = dbf.newDocumentBuilder(); 8: ... 9: try{ 10: dbf = DocumentBuilderFactory.newInstance(); 11: dbf.setNamespaceAware(true); 12: ... 13: dbf = DocumentBuilderFactory.newInstance(); 14: dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,false);
public void setIgnoringComments(boolean ignoreComments)
Specifies that the parser produced by this code will ignore comments. By default the value of this is set tofalse.
- Parameters:
ignoreComments-booleanvalue to ignore comments during processing
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: try { 6: DocumentBuilderFactory factory = 7: ... 8: DocumentBuilderFactory.newInstance(); 9: 10: ... 11: factory.setExpandEntityReferences(isExpandEntityReferences()); 12: factory.setIgnoringComments(isIgnoringComments());
1: { 2: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 3: 4: DocumentBuilder parser = factory.newDocumentBuilder();
1: { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: ... 6: factory.setIgnoringComments(true); 7: factory.setIgnoringElementContentWhitespace(true);
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: Document doc = null; 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: dbf.setValidating(false); 8: ... 9: dbf.setIgnoringComments(false); 10: dbf.setIgnoringElementContentWhitespace(false);
public void setIgnoringElementContentWhitespace(boolean whitespace)
Specifies that the parsers created by this factory must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing XML documents (see XML Rec 2.10). Note that only whitespace which is directly contained within element content that has an element only content model (see XML Rec 3.2.1) will be eliminated. Due to reliance on the content model this setting requires the parser to be in validating mode. By default the value of this is set tofalse.
- Parameters:
whitespace- true if the parser created must eliminate whitespace in the element content when parsing XML documents; false otherwise.
1: { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: factory.setIgnoringComments(true); 6: ... 7: factory.setIgnoringElementContentWhitespace(true); 8: factory.setValidating(true);
1: 2: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3: 4: ... 5: dbf.setValidating(false); 6: dbf.setIgnoringElementContentWhitespace(false); 7: dbf.setExpandEntityReferences(true); 8: dbf.setCoalescing(true);
1: 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: Document doc = null; 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: dbf.setValidating(false); 8: ... 9: dbf.setIgnoringComments(false); 10: dbf.setIgnoringElementContentWhitespace(false); 11: dbf.setNamespaceAware(true);
1: { 2: DocumentBuilderFactory Factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: 6: ... 7: Factory.setNamespaceAware(true); 8: Factory.setIgnoringElementContentWhitespace(true); 9: Factory.setIgnoringComments(true);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory 7: { 8: ... 9: protected Schema _Schema; 10: protected DocumentBuilderFactory _WrappedFactory; 11: 12: ... 13: public void setIgnoringElementContentWhitespace(boolean whitespace) 14: { _WrappedFactory.setIgnoringElementContentWhitespace(whitespace); }
public void setNamespaceAware(boolean awareness)
Specifies that the parser produced by this code will provide support for XML namespaces. By default the value of this is set tofalse
- Parameters:
awareness- true if the parser produced will provide support for XML namespaces; false otherwise.
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: { 6: DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 7: ... 8: dfactory.setNamespaceAware(true); 9: DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); 10: ... 11: DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 12: dfactory.setNamespaceAware(true);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import org.w3c.dom.Document; 4: ... 5: public void parse(InputStream document, OutputStream finf, String workingDirectory) throws Exception { 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: ... 8: dbf.setNamespaceAware(true); 9: DocumentBuilder db = dbf.newDocumentBuilder();
1: import javax.xml.transform.stream.StreamResult; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: ... 8: dbf.setNamespaceAware(true); 9: Document doc = dbf.newDocumentBuilder().parse(args[0]);
1: import javax.xml.transform.stream.StreamResult; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: ... 8: dbf.setNamespaceAware(true); 9: Document doc = dbf.newDocumentBuilder().parse(args[0]);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import org.apache.xml.security.c14n.Canonicalizer; 4: ... 5: 6: DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 7: ... 8: dfactory.setNamespaceAware(true); 9: dfactory.setValidating(true);
public void setSchema(Schema schema)
Set theSchemato be used by parsers created from this factory. When aSchemais non-null, a parser will use a validator created from it to validate documents before it passes information down to the application. When errors are found by the validator, the parser is responsible to report them to the user-specifiedDOMErrorHandler(or if the error handler is not set, ignore them or throw them), just like any other errors found by the parser itself. In other words, if the user-specifiedDOMErrorHandleris set, it must receive those errors, and if not, they must be treated according to the implementation specific default error handling rules. A validator may modify the outcome of a parse (for example by adding default values that were missing in documents), and a parser is responsible to make sure that the application will receive modified DOM trees. Initialy, null is set as theSchema. This processing will take effect even if theisValidating()method returns false. It is an error to use thehttp://java.sun.com/xml/jaxp/properties/schemaSourceproperty and/or thehttp://java.sun.com/xml/jaxp/properties/schemaLanguageproperty in conjunction with aSchemaobject. Such configuration will cause aParserConfigurationExceptionexception when thenewDocumentBuilder()is invoked.Note for implmentors
A parser must be able to work with anySchemaimplementation. However, parsers and schemas are allowed to use implementation-specific custom mechanisms as long as they yield the result described in the specification.
- Parameters:
schema-Schemato use ornullto remove a schema.
- Throws:
UnsupportedOperationException- For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
- Since:
- 1.5
1: import javax.xml.XMLConstants; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: void setAttr(boolean setSrc) { 6: DocumentBuilderFactory docBFactory = DocumentBuilderFactory.newInstance(); 7: Schema sch = createSchema(); 8: ... 9: docBFactory.setSchema(sch); 10: docBFactory.setNamespaceAware(true);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.SAXParserFactory; 4: ... 5: public void testDomPrewire() throws Exception { 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: dbf.setNamespaceAware(true); 8: ... 9: dbf.setSchema(loadXsdSchema("Camera.xsd")); 10: DocumentBuilder builder = dbf.newDocumentBuilder(); 11: ... 12: spf.setNamespaceAware(true); 13: spf.setSchema(loadXsdSchema("Camera.xsd"));
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: 4: ... 5: public void test1() throws Exception { 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: System.out.println(Which4J.which(dbf.getClass())); 8: ... 9: dbf.setSchema(loadKSchema()); 10: DocumentBuilder db = dbf.newDocumentBuilder(); 11: ... 12: System.out.println(Which4J.which(dbf.getClass())); 13: dbf.setSchema(loadXsdSchema("Test2.xsd"));
public void setValidating(boolean validating)
Specifies that the parser produced by this code will validate documents as they are parsed. By default the value of this is set tofalse. Note that "the validation" here means a validating parser as defined in the XML recommendation. In other words, it essentially just controls the DTD validation. (except the legacy two properties defined in JAXP 1.2. See here for more details.) To use modern schema languages such as W3C XML Schema or RELAX NG instead of DTD, you can configure your parser to be a non-validating parser by leaving thesetValidating(boolean)method false, then use thesetSchema(Schema)method to associate a schema to a parser.
- Parameters:
validating- true if the parser produced will validate documents as they are parsed; false otherwise.
1: public DOMTest2(String uri) throws Exception { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: ... 6: factory.setValidating(true); 7: DocumentBuilder builder = factory.newDocumentBuilder();
1: public DOMTest6() throws Exception { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: ... 6: factory.setValidating(true); 7: DocumentBuilder builder = factory.newDocumentBuilder();
1: public DOMTest4(String uri) throws Exception { 2: DocumentBuilderFactory factory = 3: ... 4: DocumentBuilderFactory.newInstance(); 5: ... 6: factory.setValidating(true); 7: DocumentBuilder builder = factory.newDocumentBuilder();
public void setXIncludeAware(boolean state)
Set state of XInclude processing. If XInclude markup is found in the document instance, should it be processed as specified in XML Inclusions (XInclude) Version 1.0. XInclude processing defaults tofalse.
- Parameters:
state- Set XInclude processing totrueorfalse
- Throws:
UnsupportedOperationException- For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
- Since:
- 1.5
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import org.w3c.dom.DOMError; 4: ... 5: try{ 6: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 7: ... 8: dbf.setXIncludeAware(true); 9: dbf.setNamespaceAware(true);
1: import javax.xml.parsers.DocumentBuilder; 2: import javax.xml.parsers.DocumentBuilderFactory; 3: import javax.xml.parsers.ParserConfigurationException; 4: ... 5: { 6: DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); 7: ... 8: f.setXIncludeAware(true); 9: f.setNamespaceAware(namespaceAware);