/* * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * Defines the Java APIs for XML Processing (JAXP). * *
* * Processors are aggregates of parsers (or readers), serializers (or writers), * validators, and transformers that control and perform the processing in their * respective areas. They are defined in their relevant packages. * In the {@link javax.xml.parsers parsers} package for example, * are the {@link javax.xml.parsers.DocumentBuilder DocumentBuilder} and * {@link javax.xml.parsers.SAXParser SAXParser}, that represent the DOM and * SAX processors. *
* The processors are configured and instantiated with their corresponding factories. * The DocumentBuilder and SAXParser for example are constructed with the * {@link javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory} * and {@link javax.xml.parsers.SAXParserFactory SAXParserFactory} respectively. * *
* The exact time at which system properties are read is unspecified. In order to * ensure that the desired values are properly applied, applications should ensure * that system properties are set appropriately prior to the creation of the first * JAXP factory and are not modified thereafter. * *
* Configuration files are Java {@link java.util.Properties} files that consist * of mappings between system properties and their values defined by various APIs * or processes. The following configuration file entries demonstrate setting the * {@code javax.xml.parsers.DocumentBuilderFactory} * and {@code CatalogFeatures.RESOLVE} properties: * * {@snippet : * javax.xml.parsers.DocumentBuilderFactory=packagename.DocumentBuilderFactoryImpl * javax.xml.catalog.resolve=strict * } * *
* The {@code jaxp.properties} file will be read only once during the initialization * of the JAXP implementation and cached in memory. If there is an error accessing * or reading the file, the configuration process proceeds as if the file does not exist. * *
* When the {@code java.xml.config.file} is specified, the configuration file will be * read and the included properties will override the same properties that were * defined in the {@code jaxp.properties} file. If the {@code java.xml.config.file} * has not been set when the JAXP implementation is initialized, no further attempt * will be made to check for its existence. *
* The {@code java.xml.config.file} value must contain a valid pathname * to a configuration file. If the pathname is not absolute, it will be considered * relative to the working directory of the JVM. * If there is an error reading the configuration file, the configuration process * proceeds as if the {@code java.xml.config.file} property was not set. * Implementations may optionally issue a warning message. * *
* The APIs for factories or processors *
* System Property *
* User-defined Configuration File *
* The default JAXP Configuration File {@code jaxp.properties} *
* The default values for JAXP Properties. If the * {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING FSP} is true, * the default values will be set to process XML securely. *
* Properties specified with factory or processor APIs have the highest * precedence. The following code effectively sets the RESOLVE property to * {@code strict}, regardless of settings in any other configuration sources. * * {@snippet : * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); * dbf.setAttribute(CatalogFeatures.Feature.RESOLVE.getPropertyName(), "strict"); * } * *
* If the property is not set on the factory as in the above code, a * system property setting will be in effect. * {@snippet : * // in the following example, the RESOLVE property is set to 'continue' * // for the entire application * java -Djavax.xml.catalog.resolve=continue myApp * } *
* If the property is not set on the factory, or using a system property, * the setting in a configuration file will take effect. The following entry * sets the property to '{@code continue}'. * {@snippet : * javax.xml.catalog.resolve=continue * } * *
* If the property is not set anywhere, it will be resolved to its * default value that is '{@code strict}'. *
| Factory | *Method | *System Property | *System Default | *
|---|---|---|---|
| * {@link javax.xml.datatype.DatatypeFactory DatatypeFactory} * | *{@link javax.xml.datatype.DatatypeFactory#newInstance() newInstance()} | *{@code javax.xml.datatype.DatatypeFactory} | *{@link javax.xml.datatype.DatatypeFactory#newDefaultInstance() newDefaultInstance()} | *
| * {@link javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory} * | *{@link javax.xml.parsers.DocumentBuilderFactory#newInstance() newInstance()} | *{@code javax.xml.parsers.DocumentBuilderFactory} | *{@link javax.xml.parsers.DocumentBuilderFactory#newDefaultInstance() newDefaultInstance()} | *
| * {@link javax.xml.parsers.SAXParserFactory SAXParserFactory} * | *{@link javax.xml.parsers.SAXParserFactory#newInstance() newInstance()} | *{@code javax.xml.parsers.SAXParserFactory} | *{@link javax.xml.parsers.SAXParserFactory#newDefaultInstance() newDefaultInstance()} | *
| * {@link javax.xml.stream.XMLEventFactory XMLEventFactory} * | *{@link javax.xml.stream.XMLEventFactory#newFactory() newFactory()} | *{@code javax.xml.stream.XMLEventFactory} | *{@link javax.xml.stream.XMLEventFactory#newDefaultFactory() newDefaultFactory()} | *
| * {@link javax.xml.stream.XMLInputFactory XMLInputFactory} * | *{@link javax.xml.stream.XMLInputFactory#newFactory() newFactory()} | *{@code javax.xml.stream.XMLInputFactory} | *{@link javax.xml.stream.XMLInputFactory#newDefaultFactory() newDefaultFactory()} | *
| * {@link javax.xml.stream.XMLOutputFactory XMLOutputFactory} * | *{@link javax.xml.stream.XMLOutputFactory#newFactory() newFactory()} | *{@code javax.xml.stream.XMLOutputFactory} | *{@link javax.xml.stream.XMLOutputFactory#newDefaultFactory() newDefaultFactory()} | *
| * {@link javax.xml.transform.TransformerFactory TransformerFactory} * | *{@link javax.xml.transform.TransformerFactory#newInstance() newInstance()} | *{@code javax.xml.transform.TransformerFactory} | *{@link javax.xml.transform.TransformerFactory#newDefaultInstance() newDefaultInstance()} | *
| * {@link javax.xml.validation.SchemaFactory SchemaFactory} * | *{@link javax.xml.validation.SchemaFactory#newInstance(java.lang.String) newInstance(schemaLanguage)} | *{@code javax.xml.validation.SchemaFactory:}schemaLanguage[1] | *{@link javax.xml.validation.SchemaFactory#newDefaultInstance() newDefaultInstance()} | *
| * {@link javax.xml.xpath.XPathFactory XPathFactory} * | *{@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)} | *{@link javax.xml.xpath.XPathFactory#DEFAULT_PROPERTY_NAME DEFAULT_PROPERTY_NAME} + ":uri"[2] | *{@link javax.xml.xpath.XPathFactory#newDefaultInstance() newDefaultInstance()} | *
* [2] where uri is the parameter to the * {@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)} * method. * *
* The Configuration File *
* The service-provider loading facility, defined by the * {@link java.util.ServiceLoader} class, to attempt to locate and load an * implementation of the service using the {@linkplain * java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: * the service-provider loading facility will use the {@linkplain * java.lang.Thread#getContextClassLoader() current thread's context class loader} * to attempt to load the service. If the context class * loader is null, the {@linkplain * ClassLoader#getSystemClassLoader() system class loader} will be used. * *
* Otherwise, the {@code system-default} implementation is returned, which is * equivalent to calling the {@code newDefaultInstance() or newDefaultFactory()} * method as shown in column System Default of the table * JAXP Factories above. * *
| Source | *Files | *
|---|---|
| * {@link java.util.prefs.Preferences java.util.prefs.Preferences} | ** preferences.dtd * | *
| * {@link java.util.Properties java.util.Properties} | ** properties.dtd * | *
|
* XML Schema Part 1: Structures Second Edition * XML Schema Part 2: Datatypes Second Edition * |
*
* XMLSchema.dtd * datatypes.dtd * XMLSchema.xsd * datatypes.xsd * |
*
| * XHTML™ 1.0 The Extensible HyperText Markup Language * | *
* xhtml1-frameset.dtd * xhtml1-strict.dtd * xhtml1-transitional.dtd * |
*
| * XHTML™ 1.0 in XML Schema * | *
* xhtml1-frameset.xsd * xhtml1-strict.xsd * xhtml1-transitional.xsd * |
*
| * XHTML™ 1.1 - Module-based XHTML - Second Edition * | ** xhtml11.dtd * | *
| * XHTML 1.1 XML Schema Definition * | ** xhtml11.xsd * | *
| * XML DTD for W3C specifications * | ** xmlspec.dtd * | *
| * The "xml:" Namespace * | ** xml.xsd * | *
* The catalog is loaded once when the first JAXP processor factory is created. * *
* XML processors may use resolvers (such as {@link org.xml.sax.EntityResolver EntityResolver}, * {@link javax.xml.stream.XMLResolver XMLResolver}, and {@link javax.xml.catalog.CatalogResolver CatalogResolver}) * to handle external references. In the absence of the user-defined resolvers, * the JDK XML processors fall back to the default CatalogResolver to attempt to * find a resolution before making a connection to fetch the resources. The fall-back * also takes place if a user-defined resolver exists but allows the process to * continue when unable to resolve the resource. *
* If the default CatalogResolver is unable to locate a resource, it may signal * the XML processors to continue processing, or skip the resource, or * throw a CatalogException. The behavior is configured with the * {@code jdk.xml.jdkcatalog.resolve} property. * *
* Refer to the Implementation Specific Properties table * for the list of properties supported by the JDK implementation. * *
| ID | *Name | *Method 1: setAttribute/Parameter/Property | *Method 2: setFeature | *
|---|---|---|---|
| DOM | *DOM Parser | *
* {@code DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();} * {@code dbf.setAttribute(name, value);} * |
*
* {@code DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();} * {@code dbf.setFeature(name, value);} * |
*
| SAX | *SAX Parser | *
* {@code SAXParserFactory spf = SAXParserFactory.newInstance();} * {@code SAXParser parser = spf.newSAXParser();} * {@code parser.setProperty(name, value);} * |
*
* {@code SAXParserFactory spf = SAXParserFactory.newInstance();} * {@code spf.setFeature(name, value);} * |
*
| StAX | *StAX Parser | *
* {@code XMLInputFactory xif = XMLInputFactory.newInstance();} * {@code xif.setProperty(name, value);} * |
*
* {@code XMLInputFactory xif = XMLInputFactory.newInstance();} * {@code xif.setProperty(name, value);} * |
*
| Validation | *XML Validation API | *
* {@code SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);} * {@code schemaFactory.setProperty(name, value);} * |
*
* {@code SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);} * {@code schemaFactory.setFeature(name, value);} * |
*
| Transform | *XML Transform API | *
* {@code TransformerFactory factory = TransformerFactory.newInstance();} * {@code factory.setAttribute(name, value);} * |
*
* {@code TransformerFactory factory = TransformerFactory.newInstance();} * {@code factory.setFeature(name, value);} * |
*
| XSLTC Serializer | *XSLTC Serializer | *
* {@code Transformer transformer = TransformerFactory.newInstance().newTransformer();} * {@code transformer.setOutputProperty(name, value);} * |
* * | *
| DOMLS | *DOM Load and Save | *
* {@code LSSerializer serializer = domImplementation.createLSSerializer();} * {@code serializer.getDomConfig().setParameter(name, value);} * |
* * | *
| XPath | *XPath | *
* {@code XPathFactory factory = XPathFactory.newInstance();} * {@code factory.setProperty(name, value);} * |
*
* {@code XPathFactory factory = XPathFactory.newInstance();} * {@code factory.setFeature(name, value);} * |
*
| Full Name (prefix {@code jdk.xml.}) * [1] | *Description | *System Property [2] | *Value [3] | *Security [4] | *Supported Processor [5] | *Since [6] | *||||
|---|---|---|---|---|---|---|---|---|---|---|
| Type | *Value | *Default | *Enforced | *ID | *Set Method | *|||||
| {@systemProperty jdk.xml.entityExpansionLimit} | *Limits the number of entity expansions. * | *yes | *Integer | ** A positive integer. A value less than or equal to 0 indicates no limit. * If the value is not an integer, a NumberFormatException is thrown. * | *2500 | *2500 | *Yes | *
* DOM * SAX * StAX * Validation * Transform * |
* Method 1 | *8 | *
| {@systemProperty jdk.xml.elementAttributeLimit} | *Limits the number of attributes an element can have. * | *200 | *200 | *|||||||
| {@systemProperty jdk.xml.maxOccurLimit} | *Limits the number of content model nodes that may be created when building * a grammar for a W3C XML Schema that contains maxOccurs attributes with values * other than "unbounded". * | *5000 | *5000 | *|||||||
| {@systemProperty jdk.xml.totalEntitySizeLimit} | *Limits the total size of all entities that include general and parameter * entities. The size is calculated as an aggregation of all entities. * | *100000 | *100000 | *|||||||
| {@systemProperty jdk.xml.maxGeneralEntitySizeLimit} | *Limits the maximum size of any general entities. * | *100000 | *100000 | *|||||||
| {@systemProperty jdk.xml.maxParameterEntitySizeLimit} | *Limits the maximum size of any parameter entities, including the result * of nesting multiple parameter entities. * | *15000 | *15000 | *|||||||
| {@systemProperty jdk.xml.entityReplacementLimit} | *Limits the total number of nodes in all entity references. * | *100000 | *100000 | *|||||||
| {@systemProperty jdk.xml.maxElementDepth} | *Limits the maximum element depth. * | *100 | *100 | *|||||||
| {@systemProperty jdk.xml.maxXMLNameLimit} | *Limits the maximum size of XML names, including element name, attribute * name and namespace prefix and URI. * | *1000 | *1000 | *|||||||
| {@systemProperty jdk.xml.isStandalone} | *Indicates that the serializer should treat the output as a * standalone document. The property can be used to ensure a newline is written * after the XML declaration. Unlike the property * {@link org.w3c.dom.ls.LSSerializer#getDomConfig() xml-declaration}, this property * does not have an effect on whether an XML declaration should be written out. * | *boolean | *true/false | *false | *N/A | *No | *DOMLS | *17 | *||
| {@systemProperty jdk.xml.xsltcIsStandalone} | *Indicates that the XSLTC serializer should
* treat the output as a standalone document. The property can be used to ensure
* a newline is written after the XML declaration. Unlike the property
* {@link javax.xml.transform.OutputKeys#OMIT_XML_DECLARATION OMIT_XML_DECLARATION},
* this property does not have an effect on whether an XML declaration should be
* written out.
* * This property behaves similar to that for DOMLS above, * except that it is for the XSLTC Serializer * and its value is a String. * |
* String | *yes/no | *no | *N/A | *No | *XSLTC Serializer | *17 | *||
| {@systemProperty jdk.xml.cdataChunkSize} | *Instructs the parser to return the data in a CData section in a single chunk * when the property is zero or unspecified, or in multiple chunks when it is greater * than zero. The parser shall split the data by linebreaks, and any chunks that are * larger than the specified size to ones that are equal to or smaller than the size. * | *yes | *Integer | *A positive integer. A value less than * or equal to 0 indicates that the property is not specified. If the value is not * an integer, a NumberFormatException is thrown. | *0 | *N/A | *No | *SAX StAX |
* 9 | *|
| jdk.xml.extensionClassLoader | *Sets a non-null ClassLoader instance to be used for loading XSLTC java * extension functions. * | *no | *Object | *A reference to a ClassLoader object. Null if the value is not specified. | *null | *N/A | *No | *Transform | *9 | *|
| jdk.xml.xpathExprGrpLimit | *Limits the number of groups an XPath expression can contain. * | *yes | *Integer | *A positive integer. A value less than or equal to 0 indicates no limit. * If the value is not an integer, a NumberFormatException is thrown. | *10 | *10 | *Yes | *
* Transform * XPath * |
* 19 | *|
| jdk.xml.xpathExprOpLimit | *Limits the number of operators an XPath expression can contain. * | *100 | *100 | *|||||||
| jdk.xml.xpathTotalOpLimit | *Limits the total number of XPath operators in an XSL Stylesheet. * | *10000 | *10000 | *
* Transform * |
* ||||||
| {@systemProperty jdk.xml.enableExtensionFunctions} | *Determines if XSLT and XPath extension functions are to be allowed. * | *yes | *Boolean | ** true or false. True indicates that extension functions are allowed; False otherwise. * | *true | *false | *Yes | *
* Transform * XPath * |
* Method 2 | *8 | *
| {@systemProperty jdk.xml.overrideDefaultParser} | *Enables the use of a 3rd party's parser implementation to override the * system-default parser for the JDK's Transform, Validation and XPath implementations. * | ** true or false. True enables the use of 3rd party's parser implementations * to override the system-default implementation during XML Transform, Validation * or XPath operation. False disables the use of 3rd party's parser * implementations. * | *false | *false | *Yes | *
* Transform * Validation * XPath * |
* Method 2 | *9 | *||
| {@systemProperty jdk.xml.resetSymbolTable} | *Instructs the parser to reset its internal symbol table during each parse operation. * | *
* true or false. True indicates that the SymbolTable associated with a parser needs to be
* reallocated during each parse operation. * False indicates that the parser's SymbolTable instance shall be reused * during subsequent parse operations. * |
* false | *N/A | *No | ** SAX * | *Method 2 | *9 | *||
| {@systemProperty jdk.xml.dtd.support}[7] | *Instructs the parser to handle DTDs in accordance with the setting of this property.
* The options are:
*
|
* String | ** {@code allow, ignore, and deny}. Values are case-insensitive. * | *allow | *No | *Yes | *
* DOM * SAX * StAX * Validation * Transform * |
* Method 1 | *22 | *|
| {@systemProperty jdk.xml.jdkcatalog.resolve} | *Instructs the JDK default CatalogResolver to act in accordance with the setting
* of this property when unable to resolve an external reference with the built-in Catalog.
* The options are:
*
|
* String | ** {@code continue, ignore, and strict}. Values are case-insensitive. * | *continue | *No | *Yes | *
* DOM * SAX * StAX * Validation * Transform * |
* Method 1 | *22 | *|
* [1] The full name of a property should be used to set the property. *
* [2] A value "yes" indicates there is a corresponding System Property * for the property, "no" otherwise. The name of the System Property is the same * as that of the property. * *
* [3] The value must be exactly as listed in this table, case-sensitive. * The value of the corresponding System Property is the String representation of * the property value. If the type is boolean, the system property is true only * if it is "true"; If the type is String, the system property is true only if * it is exactly the same string representing the positive value (e.g. "yes" for * {@code xsltcIsStandalone}); The system property is false otherwise. If the type * is Integer, the value of the System Property is the String representation of * the value (e.g. "64000" for {@code entityExpansionLimit}). * *
* [4] A value "yes" indicates the property is a Security Property. As indicated * in the Property Precedence, the values listed in the column * {@code enforced} will be used to initialize these properties when * {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING FSP} is true. * *
* [5] One or more processors that support the property. The IDs and Set Method * are as shown in the table Processors. *
* [6] Indicates the initial release the property is introduced. *
* [7] The {@code jdk.xml.dtd.support} property complements the two existing * DTD-related properties, {@code disallow-doctype-decl}(fully qualified name: * {@code http://apache.org/xml/features/disallow-doctype-decl}) and supportDTD * ({@code javax.xml.stream.supportDTD}), by providing a uniformed support for the * processors listed and a system property that can be used in the * JAXP Configuration File. When {@code disallow-doctype-decl} is * set on the DOM or SAX factory, or supportDTD on StAX factory, the {@code jdk.xml.dtd.support} * property will have no effect. *
* These three properties control whether DTDs as a whole shall be processed. When * they are set to deny or ignore, other properties that regulate a part or an * aspect of DTD shall have no effect. * *
* The following table lists the properties and their corresponding legacy names. * *
| Property | *Legacy Property Name(s) | *
|---|---|
| {@systemProperty jdk.xml.entityExpansionLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit} | *
| {@systemProperty jdk.xml.elementAttributeLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/elementAttributeLimit} | *
| {@systemProperty jdk.xml.maxOccurLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/maxOccurLimit} | *
| {@systemProperty jdk.xml.totalEntitySizeLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit} | *
| {@systemProperty jdk.xml.maxGeneralEntitySizeLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/maxGeneralEntitySizeLimit} | *
| {@systemProperty jdk.xml.maxParameterEntitySizeLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/maxParameterEntitySizeLimit} | *
| {@systemProperty jdk.xml.entityReplacementLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/entityReplacementLimit} | *
| {@systemProperty jdk.xml.maxElementDepth} | *{@code http://www.oracle.com/xml/jaxp/properties/maxElementDepth} | *
| {@systemProperty jdk.xml.maxXMLNameLimit} | *{@code http://www.oracle.com/xml/jaxp/properties/maxXMLNameLimit} | *
| {@systemProperty jdk.xml.isStandalone} | *{@code http://www.oracle.com/xml/jaxp/properties/isStandalone} | *
| {@systemProperty jdk.xml.xsltcIsStandalone} | *{@code http://www.oracle.com/xml/is-standalone} * {@code http://www.oracle.com/xml/jaxp/properties/xsltcIsStandalone} |
*
| {@code jdk.xml.extensionClassLoader} | *{@code jdk.xml.transform.extensionClassLoader} | *
| {@systemProperty jdk.xml.enableExtensionFunctions} | *{@code http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions} | *