Property Name | Behavior | Return type | Default Value | Required |
---|---|---|---|---|
javax.xml.stream.isRepairingNamespaces | defaults prefixes on the output side | Boolean | False | Yes |
The following paragraphs describe the namespace and prefix repair algorithm:
The property can be set with the following code line:
setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
This property specifies that the writer default namespace prefix declarations. The default value is false.
If a writer isRepairingNamespaces it will create a namespace declaration on the current StartElement for any attribute that does not currently have a namespace declaration in scope. If the StartElement has a uri but no prefix specified a prefix will be assigned, if the prefix has not been declared in a parent of the current StartElement it will be declared on the current StartElement. If the defaultNamespace is bound and in scope and the default namespace matches the URI of the attribute or StartElement QName no prefix will be assigned.
If an element or attribute name has a prefix, but is not bound to any namespace URI, then the prefix will be removed during serialization.
If element and/or attribute names in the same start or empty-element tag are bound to different namespace URIs and are using the same prefix then the element or the first occurring attribute retains the original prefix and the following attributes have their prefixes replaced with a new prefix that is bound to the namespace URIs of those attributes.
If an element or attribute name uses a prefix that is bound to a different URI than that inherited from the namespace context of the parent of that element and there is no namespace declaration in the context of the current element then such a namespace declaration is added.
If an element or attribute name is bound to a prefix and there is a namespace declaration that binds that prefix to a different URI then that namespace declaration is either removed if the correct mapping is inherited from the parent context of that element, or changed to the namespace URI of the element or attribute using that prefix.
- Since:
- 1.6
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property used to set prefix defaulting on the output side -
Constructor Summary
ModifierConstructorDescriptionprotected
Protected constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionabstract XMLEventWriter
createXMLEventWriter
(OutputStream stream) Create a new XMLEventWriter that writes to a streamabstract XMLEventWriter
createXMLEventWriter
(OutputStream stream, String encoding) Create a new XMLEventWriter that writes to a streamabstract XMLEventWriter
createXMLEventWriter
(Writer stream) Create a new XMLEventWriter that writes to a writerabstract XMLEventWriter
createXMLEventWriter
(Result result) Create a new XMLEventWriter that writes to a JAXP result.abstract XMLStreamWriter
createXMLStreamWriter
(OutputStream stream) Create a new XMLStreamWriter that writes to a streamabstract XMLStreamWriter
createXMLStreamWriter
(OutputStream stream, String encoding) Create a new XMLStreamWriter that writes to a streamabstract XMLStreamWriter
createXMLStreamWriter
(Writer stream) Create a new XMLStreamWriter that writes to a writerabstract XMLStreamWriter
createXMLStreamWriter
(Result result) Create a new XMLStreamWriter that writes to a JAXP result.abstract Object
getProperty
(String name) Get a feature/property on the underlying implementationabstract boolean
isPropertySupported
(String name) Query the set of properties that this factory supports.static XMLOutputFactory
Creates a new instance of theXMLOutputFactory
builtin system-default implementation.static XMLOutputFactory
Creates a new instance of the factory.static XMLOutputFactory
newFactory
(String factoryId, ClassLoader classLoader) Create a new instance of the factory.static XMLOutputFactory
Creates a new instance of the factory in exactly the same manner as thenewFactory()
method.static XMLInputFactory
newInstance
(String factoryId, ClassLoader classLoader) Deprecated.This method has been deprecated because it returns an instance of XMLInputFactory, which is of the wrong class.abstract void
setProperty
(String name, Object value) Allows the user to set specific features/properties on the underlying implementation.
-
Field Details
-
IS_REPAIRING_NAMESPACES
Property used to set prefix defaulting on the output side- See Also:
-
-
Constructor Details
-
XMLOutputFactory
protected XMLOutputFactory()Protected constructor to prevent instantiation. UsenewFactory()
instead.
-
-
Method Details
-
newDefaultFactory
Creates a new instance of theXMLOutputFactory
builtin system-default implementation.- Returns:
- A new instance of the
XMLOutputFactory
builtin system-default implementation. - Since:
- 9
-
newInstance
Creates a new instance of the factory in exactly the same manner as thenewFactory()
method.- Returns:
- an instance of the
XMLOutputFactory
- Throws:
FactoryConfigurationError
- if an instance of this factory cannot be loaded
-
newFactory
Creates a new instance of the factory. This method uses the JAXP Lookup Mechanism to determine theXMLOutputFactory
implementation class to load.Once an application has obtained a reference to a
XMLOutputFactory
, it can use the factory to configure and obtain stream instances.- Returns:
- an instance of the
XMLOutputFactory
- Throws:
FactoryConfigurationError
- in case of service configuration error or if the implementation is not available or cannot be instantiated.
-
newInstance
@Deprecated(since="1.7") public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError Deprecated.This method has been deprecated because it returns an instance of XMLInputFactory, which is of the wrong class. Use the new methodnewFactory(java.lang.String, java.lang.ClassLoader)
instead.Create a new instance of the factory.- Parameters:
factoryId
- Name of the factory to find, same as a property nameclassLoader
- classLoader to use- Returns:
- the factory implementation
- Throws:
FactoryConfigurationError
- if an instance of this factory cannot be loaded
-
newFactory
public static XMLOutputFactory newFactory(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError Create a new instance of the factory. If the classLoader argument is null, then the ContextClassLoader is used.This method uses the following ordered lookup procedure to determine the XMLOutputFactory implementation class to load:
-
Use the value of the system property identified by
factoryId
. -
Use the configuration file "stax.properties". The file is in standard
Properties
format and typically located in theconf
directory of the Java installation. It contains the fully qualified name of the implementation class with the key being the system property defined above.The stax.properties file is read only once by the implementation and its 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 stax.properties after it has been read for the first time.
Use the jaxp configuration file "jaxp.properties". The file is in the same format as stax.properties and will only be read if stax.properties does not exist.
-
If
factoryId
is "javax.xml.stream.XMLOutputFactory", use the service-provider loading facility, defined by theServiceLoader
class, to attempt to locate and load an implementation of the service using the specifiedClassLoader
. IfclassLoader
is null, the default loading mechanism will apply: That is, the service-provider loading facility will use the current thread's context class loader to attempt to load the service. If the context class loader is null, the system class loader will be used. -
Otherwise, throws a
FactoryConfigurationError
.
- API Note:
- The parameter factoryId defined here is inconsistent with that
of other JAXP factories where the first parameter is fully qualified
factory class name that provides implementation of the factory.
Note that this is a new method that replaces the deprecated
newInstance(String factoryId, ClassLoader classLoader)
method. The original method was incorrectly defined to return XMLInputFactory. - Parameters:
factoryId
- Name of the factory to find, same as a property nameclassLoader
- classLoader to use- Returns:
- the factory implementation
- Throws:
FactoryConfigurationError
- in case of service configuration error or if the implementation is not available or cannot be instantiated.
-
Use the value of the system property identified by
-
createXMLStreamWriter
Create a new XMLStreamWriter that writes to a writer- Parameters:
stream
- the writer to write to- Returns:
- instance of the
XMLStreamWriter
- Throws:
XMLStreamException
- if an error occurs
-
createXMLStreamWriter
public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream) throws XMLStreamException Create a new XMLStreamWriter that writes to a stream- Parameters:
stream
- the stream to write to- Returns:
- instance of the
XMLStreamWriter
- Throws:
XMLStreamException
- if an error occurs
-
createXMLStreamWriter
public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) throws XMLStreamException Create a new XMLStreamWriter that writes to a stream- Parameters:
stream
- the stream to write toencoding
- the encoding to use- Returns:
- instance of the
XMLStreamWriter
- Throws:
XMLStreamException
- if an error occurs
-
createXMLStreamWriter
Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.- Parameters:
result
- the result to write to- Returns:
- instance of the
XMLStreamWriter
- Throws:
UnsupportedOperationException
- if this method is not supported by this XMLOutputFactoryXMLStreamException
- if an error occurs
-
createXMLEventWriter
Create a new XMLEventWriter that writes to a JAXP result. This method is optional.- Parameters:
result
- the result to write to- Returns:
- instance of the
XMLEventWriter
- Throws:
UnsupportedOperationException
- if this method is not supported by this XMLOutputFactoryXMLStreamException
- if an error occurs
-
createXMLEventWriter
Create a new XMLEventWriter that writes to a stream- Parameters:
stream
- the stream to write to- Returns:
- instance of the
XMLEventWriter
- Throws:
XMLStreamException
- if an error occurs
-
createXMLEventWriter
public abstract XMLEventWriter createXMLEventWriter(OutputStream stream, String encoding) throws XMLStreamException Create a new XMLEventWriter that writes to a stream- Parameters:
stream
- the stream to write toencoding
- the encoding to use- Returns:
- instance of the
XMLEventWriter
- Throws:
XMLStreamException
- if an error occurs
-
createXMLEventWriter
Create a new XMLEventWriter that writes to a writer- Parameters:
stream
- the stream to write to- Returns:
- instance of the
XMLEventWriter
- Throws:
XMLStreamException
- if an error occurs
-
setProperty
Allows the user to set specific features/properties on the underlying implementation.- Parameters:
name
- The name of the propertyvalue
- The value of the property- Throws:
IllegalArgumentException
- if the property is not supported
-
getProperty
Get a feature/property on the underlying implementation- Parameters:
name
- The name of the property- Returns:
- The value of the property
- Throws:
IllegalArgumentException
- if the property is not supported
-
isPropertySupported
Query the set of properties that this factory supports.- Parameters:
name
- The name of the property (may not be null)- Returns:
- true if the property is supported and false otherwise
-