XMLOutputFactory (Java EE 5)

Java EE API


javax.xml.stream Class XMLOutputFactory

java.lang.Object
  extended by javax.xml.stream.XMLOutputFactory

public abstract class XMLOutputFactory
extends Object


定义用于获取 XMLEventWriter 和 XMLStreamWriter 的工厂抽象实现。下表定义此规范的标准属性。每个属性随每个实现所要求的支持级别的不同而不同。所要求的支持级别在“必需”栏中做了描述。
配置参数
属性名 行为 返回类型 默认值 必需

以下段落描述了名称空间和前缀修复算法:

属性可以使用以下代码行进行设置:setProperty("javax.xml.stream.isRepairingNamespaces",new Boolean(true|false));

此属性指定 writer 默认名称空间前缀声明。默认值为 false。

如果 writer 是 RepairingNamespaces,则对于任何当前在范围内不具有名称空间声明的属性,它都将在当前的 StartElement 上创建名称空间声明。如果 StartElement 具有 URI,但没有指定前缀,则为其分配一个前缀;如果前缀未在当前 StartElement 的父级中声明,则它将在当前的 StartElement 上声明。如果 defaultNamespace 被绑定,而且在范围内默认名称空间与属性的 URI 或 StartElement QName 相匹配,则不分配任何前缀。

如果元素或属性名称具有前缀,但没有绑定到任何名称空间 URI,则前缀将在序列化时被删除。

如果同一个开始或空元素标记中的元素和/或属性名称被绑定到不同的名称空间 URI,而且使用相同的前缀,则元素或第一个出现的属性将保留原始前缀,而在它之后的属性将用绑定到这些属性名称空间 URI 的新前缀替换它们的前缀。

如果元素或属性名称使用一个绑定到 URI 的前缀,而该 URI 不是从该元素父级的名称空间上下文中继承的,并且在当前元素的上下文中没有名称空间声明,那么将添加一个这样的名称空间声明。

如果元素或属性名称被绑定到一个前缀,而且有一个将此前缀绑定到不同 RUI 的名称空间声明,那么该名称空间声明将被删除(如果从该元素的父上下文中继承了正确的映射),或者被更改为使用该前缀的元素或属性的名称空间 URI。

英文文档:

Defines an abstract implementation of a factory for getting XMLEventWriters and XMLStreamWriters. The following table defines the standard properties of this specification. Each property varies in the level of support required by each implementation. The level of support required is described in the 'Required' column.

Configuration parameters
Property Name Behavior Return type Default Value Required

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",new Boolean(true|false));

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.

Version:
1.0
Author:
Copyright (c) 2003 by BEA Systems. All Rights Reserved.
See Also:
XMLInputFactory, XMLEventWriter, XMLStreamWriter

Field Summary
static String
 
Constructor Summary
protected
 
Method Summary
abstract  XMLEventWriter
abstract  XMLEventWriter
abstract  XMLEventWriter
abstract  XMLEventWriter
abstract  XMLStreamWriter
abstract  XMLStreamWriter
abstract  XMLStreamWriter
abstract  XMLStreamWriter
abstract  Object
abstract  boolean
static XMLOutputFactory
static XMLInputFactory
abstract  void
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

IS_REPAIRING_NAMESPACES

public static final String IS_REPAIRING_NAMESPACES
Property used to set prefix defaulting on the output side

See Also:
Constant Field Values

Constructor Detail

protected XMLOutputFactory()
英文文档:

XMLOutputFactory

protected XMLOutputFactory()
Method Detail

public static XMLOutputFactory newInstance() throws FactoryConfigurationError
创建一个新的工厂实例。
ThrowsFactoryConfigurationError: 如果无法加载此工厂的实例
英文文档:

newInstance

public static XMLOutputFactory newInstance()
                                    throws FactoryConfigurationError
Create a new instance of the factory.

Throws:
FactoryConfigurationError - if an instance of this factory cannot be loaded

public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError
创建一个的新工厂实例。
factoryId 要查找的工厂的名称,与属性名称相同
classLoader 要使用的类加载器
return 工厂实现
ThrowsFactoryConfigurationError: 如果无法加载此工厂的实例
英文文档:

newInstance

public static XMLInputFactory newInstance(String factoryId,
                                          ClassLoader classLoader)
                                   throws FactoryConfigurationError
Create a new instance of the factory

Parameters:
factoryId - Name of the factory to find, same as a property name
classLoader - classLoader to use
Returns:
the factory implementation
Throws:
FactoryConfigurationError - if an instance of this factory cannot be loaded

abstract public XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException
创建一个写入到 writer 的新 XMLStreamWriter。
stream 要向其写入 XMLStreamWriter 的 writer
ThrowsXMLStreamException:
英文文档:

createXMLStreamWriter

public abstract XMLStreamWriter createXMLStreamWriter(Writer stream)
                                               throws XMLStreamException
Create a new XMLStreamWriter that writes to a writer

Parameters:
stream - the writer to write to
Throws:
XMLStreamException

abstract public XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException
创建一个写入到流的新 XMLStreamWriter。
stream 要写入的流
ThrowsXMLStreamException:
英文文档:

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
Throws:
XMLStreamException

abstract public XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream, String encoding) throws XMLStreamException
创建一个写入到流的新 XMLStreamWriter。
stream 要写入的流
encoding 要使用的编码
ThrowsXMLStreamException:
英文文档:

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 to
encoding - the encoding to use
Throws:
XMLStreamException

abstract public XMLStreamWriter createXMLStreamWriter(javax.xml.transform.Result result) throws XMLStreamException
创建一个写入到 JAXP 结果的新 XMLStreamWriter。此方法是可选的。
result 要向其写入 XMLStreamWriter 的结果
ThrowsUnsupportedOperationException: 如果此 XMLOutputFactory 不支持此方法
ThrowsXMLStreamException:
英文文档:

createXMLStreamWriter

public abstract XMLStreamWriter createXMLStreamWriter(Result result)
                                               throws XMLStreamException
Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.

Parameters:
result - the result to write to
Throws:
UnsupportedOperationException - if this method is not supported by this XMLOutputFactory
XMLStreamException

abstract public XMLEventWriter createXMLEventWriter(javax.xml.transform.Result result) throws XMLStreamException
创建一个写入到 JAXP 结果的新 XMLEventWriter。此方法是可选的。
result 要向其写入 XMLStreamWriter 的结果
ThrowsUnsupportedOperationException: 如果此 XMLOutputFactory 不支持此方法
ThrowsXMLStreamException:
英文文档:

createXMLEventWriter

public abstract XMLEventWriter createXMLEventWriter(Result result)
                                             throws XMLStreamException
Create a new XMLEventWriter that writes to a JAXP result. This method is optional.

Parameters:
result - the result to write to
Throws:
UnsupportedOperationException - if this method is not supported by this XMLOutputFactory
XMLStreamException

abstract public XMLEventWriter createXMLEventWriter(java.io.OutputStream stream) throws XMLStreamException
创建一个写入到流的新 XMLEventWriter。
stream 要写入的流
ThrowsXMLStreamException:
英文文档:

createXMLEventWriter

public abstract XMLEventWriter createXMLEventWriter(OutputStream stream)
                                             throws XMLStreamException
Create a new XMLEventWriter that writes to a stream

Parameters:
stream - the stream to write to
Throws:
XMLStreamException

abstract public XMLEventWriter createXMLEventWriter(java.io.OutputStream stream, String encoding) throws XMLStreamException
创建一个写入到流的新 XMLEventWriter。
stream 要写入的流
encoding 要使用的编码
ThrowsXMLStreamException:
英文文档:

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 to
encoding - the encoding to use
Throws:
XMLStreamException

abstract public XMLEventWriter createXMLEventWriter(java.io.Writer stream) throws XMLStreamException
创建一个写入到 writer 的新 XMLEventWriter。
stream 要写入的流
ThrowsXMLStreamException:
英文文档:

createXMLEventWriter

public abstract XMLEventWriter createXMLEventWriter(Writer stream)
                                             throws XMLStreamException
Create a new XMLEventWriter that writes to a writer

Parameters:
stream - the stream to write to
Throws:
XMLStreamException

abstract public void setProperty(String name, Object value) throws IllegalArgumentException
允许用户在底层实现上设置特定功能/属性。
name 属性的名称
value 属性的值
ThrowsIllegalArgumentException: 如果属性不受支持
英文文档:

setProperty

public abstract void setProperty(String name,
                                 Object value)
                          throws IllegalArgumentException
Allows the user to set specific features/properties on the underlying implementation.

Parameters:
name - The name of the property
value - The value of the property
Throws:
IllegalArgumentException - if the property is not supported

abstract public Object getProperty(String name) throws IllegalArgumentException
获取底层实现上的功能/属性
name 属性的名称
return 属性的值
ThrowsIllegalArgumentException: 如果属性不受支持
英文文档:

getProperty

public abstract Object getProperty(String name)
                            throws IllegalArgumentException
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

abstract public boolean isPropertySupported(String name)
查询此工厂支持的属性集合。
name 属性的名称(不可以为 null)
return 如果此属性受支持,则返回 true,否则返回 false
英文文档:

isPropertySupported

public abstract boolean isPropertySupported(String name)
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


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!