|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.xml.stream Interface XMLStreamWriter
public interface XMLStreamWriter
XMLStreamWriter 接口指定如何编写 XML。XMLStreamWriter 不在其输入中检查格式是否良好。但是,writeCharacters 方法需要转义属性值的 &、< 和 >。writeAttribute 方法将转义上述字符以及 ",以确保所有字符内容和属性值都是格式良好的。 必须单独编写每个 NAMESPACE 和 ATTRIBUTE。 如果 javax.xml.stream.isPrefixDefaulting 设置为 false,则在使用没有绑定到前缀的名称空间 URI 写入元素时将出现致命错误。 如果 javax.xml.stream.isPrefixDefaulting 设置为 true,则 XMLStreamWriter 实现必须为当前范围内遇到的每个未绑定 URI 写入前缀。
version | 1.0 |
See also | javax.xml.stream.XMLOutputFactory, javax.xml.stream.XMLStreamReader |
The XMLStreamWriter interface specifies how to write XML. The XMLStreamWriter does not perform well formedness checking on its input. However the writeCharacters method is required to escape & , < and > For attribute values the writeAttribute method will escape the above characters plus " to ensure that all character content and attribute values are well formed. Each NAMESPACE and ATTRIBUTE must be individually written. If javax.xml.stream.isPrefixDefaulting is set to false it is a fatal error if an element is written with namespace URI that has not been bound to a prefix. If javax.xml.stream.isPrefixDefaulting is set to true the XMLStreamWriter implementation must write a prefix for each unbound URI that it encounters in the current scope.
- Version:
- 1.0
- Author:
- Copyright (c) 2003 by BEA Systems. All Rights Reserved.
- See Also:
XMLOutputFactory
,XMLStreamReader
Method Summary | |
---|---|
void |
close()
Close this writer and free any resources associated with the writer. |
void |
flush()
Write any cached data to the underlying output mechanism. |
NamespaceContext |
getNamespaceContext()
Returns the current namespace context. |
String |
getPrefix(String uri)
Gets the prefix the uri is bound to |
Object |
getProperty(String name)
Get the value of a feature/property from the underlying implementation |
void |
setDefaultNamespace(String uri)
Binds a URI to the default namespace This URI is bound in the scope of the current START_ELEMENT / END_ELEMENT pair. |
void |
setNamespaceContext(NamespaceContext context)
Sets the current namespace context for prefix and uri bindings. |
void |
setPrefix(String prefix,
String uri)
Sets the prefix the uri is bound to. |
void |
writeAttribute(String localName,
String value)
Writes an attribute to the output stream without a prefix. |
void |
writeAttribute(String namespaceURI,
String localName,
String value)
Writes an attribute to the output stream |
void |
writeAttribute(String prefix,
String namespaceURI,
String localName,
String value)
Writes an attribute to the output stream |
void |
writeCData(String data)
Writes a CData section |
void |
writeCharacters(char[] text,
int start,
int len)
Write text to the output |
void |
writeCharacters(String text)
Write text to the output |
void |
writeComment(String data)
Writes an xml comment with the data enclosed |
void |
writeDefaultNamespace(String namespaceURI)
Writes the default namespace to the stream |
void |
writeDTD(String dtd)
Write a DTD section. |
void |
writeEmptyElement(String localName)
Writes an empty element tag to the output |
void |
writeEmptyElement(String namespaceURI,
String localName)
Writes an empty element tag to the output |
void |
writeEmptyElement(String prefix,
String localName,
String namespaceURI)
Writes an empty element tag to the output |
void |
writeEndDocument()
Closes any start tags and writes corresponding end tags. |
void |
writeEndElement()
Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event. |
void |
writeEntityRef(String name)
Writes an entity reference |
void |
writeNamespace(String prefix,
String namespaceURI)
Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace |
void |
writeProcessingInstruction(String target)
Writes a processing instruction |
void |
writeProcessingInstruction(String target,
String data)
Writes a processing instruction |
void |
writeStartDocument()
Write the XML Declaration. |
void |
writeStartDocument(String version)
Write the XML Declaration. |
void |
writeStartDocument(String encoding,
String version)
Write the XML Declaration. |
void |
writeStartElement(String localName)
Writes a start tag to the output. |
void |
writeStartElement(String namespaceURI,
String localName)
Writes a start tag to the output |
void |
writeStartElement(String prefix,
String localName,
String namespaceURI)
Writes a start tag to the output |
Method Detail |
---|
public void
writeStartElement(String localName) throws XMLStreamException
向输出写入一个开始标记。所有 writeStartElement 方法都在内部名称空间上下文中打开一个新的作用域。编写相应的 EndElement 导致作用域被关闭。
localName | 标记的本地名称,不可以为 null |
Throws | XMLStreamException: |
writeStartElement
void writeStartElement(String localName) throws XMLStreamException
- Writes a start tag to the output. All writeStartElement methods
open a new scope in the internal namespace context. Writing the
corresponding EndElement causes the scope to be closed.
- Parameters:
localName
- local name of the tag, may not be null- Throws:
XMLStreamException
public void
writeStartElement(String namespaceURI, String localName) throws XMLStreamException
向输出写入一个开始标记
namespaceURI | 要使用的前缀的 namespaceURI ,不可以为 null |
localName | 标记的本地名称,不可以为 null |
Throws | XMLStreamException: 如果名称空间 URI 未绑定到前缀并且 javax.xml.stream.isPrefixDefaulting 未设置为 true |
writeStartElement
void writeStartElement(String namespaceURI, String localName) throws XMLStreamException
- Writes a start tag to the output
- Parameters:
namespaceURI
- the namespaceURI of the prefix to use, may not be nulllocalName
- local name of the tag, may not be null- Throws:
XMLStreamException
- if the namespace URI has not been bound to a prefix and javax.xml.stream.isPrefixDefaulting has not been set to true
public void
writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
向输出写入一个开始标记
localName | 标记的本地名称,不可以为 null |
prefix | 标记的前缀,不可以为 null |
namespaceURI | 要绑定前缀的 URI,不可以为 null |
Throws | XMLStreamException: |
writeStartElement
void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
- Writes a start tag to the output
- Parameters:
localName
- local name of the tag, may not be nullprefix
- the prefix of the tag, may not be nullnamespaceURI
- the uri to bind the prefix to, may not be null- Throws:
XMLStreamException
public void
writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
向输出写入一个空元素标记
namespaceURI | 要绑定标记的 URI,不可以为 null |
localName | 标记的本地名称,不可以为 null |
Throws | XMLStreamException: 如果名称空间 URI 未绑定到前缀并且 javax.xml.stream.isPrefixDefaulting 未设置为 true |
writeEmptyElement
void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
- Writes an empty element tag to the output
- Parameters:
namespaceURI
- the uri to bind the tag to, may not be nulllocalName
- local name of the tag, may not be null- Throws:
XMLStreamException
- if the namespace URI has not been bound to a prefix and javax.xml.stream.isPrefixDefaulting has not been set to true
public void
writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
向输出写入一个空元素标记
prefix | 标记的前缀,不可以为 null |
localName | 标记的本地名称,不可以为 null |
namespaceURI | 要绑定标记的 URI,不可以为 null |
Throws | XMLStreamException: |
writeEmptyElement
void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
- Writes an empty element tag to the output
- Parameters:
prefix
- the prefix of the tag, may not be nulllocalName
- local name of the tag, may not be nullnamespaceURI
- the uri to bind the tag to, may not be null- Throws:
XMLStreamException
public void
writeEmptyElement(String localName) throws XMLStreamException
向输出写入一个空元素标记
localName | 标记的本地名称,不可以为 null |
Throws | XMLStreamException: |
writeEmptyElement
void writeEmptyElement(String localName) throws XMLStreamException
- Writes an empty element tag to the output
- Parameters:
localName
- local name of the tag, may not be null- Throws:
XMLStreamException
public void
writeEndElement() throws XMLStreamException
向依赖于 writer 内部状态的输出写入一个结束标记,以此确定事件的前缀和本地名称。
Throws | XMLStreamException: |
writeEndElement
void writeEndElement() throws XMLStreamException
- Writes an end tag to the output relying on the internal
state of the writer to determine the prefix and local name
of the event.
- Throws:
XMLStreamException
public void
writeEndDocument() throws XMLStreamException
关闭所有开始标记并写入相应的结束标记。
Throws | XMLStreamException: |
writeEndDocument
void writeEndDocument() throws XMLStreamException
- Closes any start tags and writes corresponding end tags.
- Throws:
XMLStreamException
public void
close() throws XMLStreamException
关闭此 writer 并释放与 writer 关联的所有资源。此方法不得关闭底层输出流。
Throws | XMLStreamException: |
close
void close() throws XMLStreamException
- Close this writer and free any resources associated with the
writer. This must not close the underlying output stream.
- Throws:
XMLStreamException
public void
flush() throws XMLStreamException
将所有缓存数据写入底层输出机制。
Throws | XMLStreamException: |
flush
void flush() throws XMLStreamException
- Write any cached data to the underlying output mechanism.
- Throws:
XMLStreamException
public void
writeAttribute(String localName, String value) throws XMLStreamException
向输出流写入一个不带前缀的属性。
localName | 属性的本地名称 |
value | 属性的值 |
Throws | IllegalStateException: 如果当前状态不允许 Attribute 写入 |
Throws | XMLStreamException: |
writeAttribute
void writeAttribute(String localName, String value) throws XMLStreamException
- Writes an attribute to the output stream without
a prefix.
- Parameters:
localName
- the local name of the attributevalue
- the value of the attribute- Throws:
IllegalStateException
- if the current state does not allow Attribute writingXMLStreamException
public void
writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
向输出流写入一个属性
prefix | 此属性的前缀 |
namespaceURI | 此属性前缀的 URI |
localName | 属性的本地名称 |
value | 属性的值 |
Throws | IllegalStateException: 如果当前状态不允许 Attribute 写入 |
Throws | XMLStreamException: 如果名称空间 URI 未绑定到前缀并且 javax.xml.stream.isPrefixDefaulting 未设置为 true |
writeAttribute
void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
- Writes an attribute to the output stream
- Parameters:
prefix
- the prefix for this attributenamespaceURI
- the uri of the prefix for this attributelocalName
- the local name of the attributevalue
- the value of the attribute- Throws:
IllegalStateException
- if the current state does not allow Attribute writingXMLStreamException
- if the namespace URI has not been bound to a prefix and javax.xml.stream.isPrefixDefaulting has not been set to true
public void
writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException
向输出流写入一个属性
namespaceURI | 此属性前缀的 URI |
localName | 属性的本地名称 |
value | 属性的值 |
Throws | IllegalStateException: 如果当前状态不允许 Attribute 写入 |
Throws | XMLStreamException: 如果名称空间 URI 未绑定到前缀并且 javax.xml.stream.isPrefixDefaulting 未设置为 true |
writeAttribute
void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException
- Writes an attribute to the output stream
- Parameters:
namespaceURI
- the uri of the prefix for this attributelocalName
- the local name of the attributevalue
- the value of the attribute- Throws:
IllegalStateException
- if the current state does not allow Attribute writingXMLStreamException
- if the namespace URI has not been bound to a prefix and javax.xml.stream.isPrefixDefaulting has not been set to true
public void
writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
向输出流写入一个名称空间。如果此方法的 prefix 参数为空字符串、"xmlns" 或 null,则此方法将委托给 writeDefaultNamespace。
prefix | 要绑定名称空间的前缀 |
namespaceURI | 要绑定前缀的 URI |
Throws | IllegalStateException: 如果当前状态不允许 Namespace 写入 |
Throws | XMLStreamException: |
writeNamespace
void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
- Writes a namespace to the output stream
If the prefix argument to this method is the empty string,
"xmlns", or null this method will delegate to writeDefaultNamespace
- Parameters:
prefix
- the prefix to bind this namespace tonamespaceURI
- the uri to bind the prefix to- Throws:
IllegalStateException
- if the current state does not allow Namespace writingXMLStreamException
public void
writeDefaultNamespace(String namespaceURI) throws XMLStreamException
向流写入默认名称空间
namespaceURI | 要绑定默认名称空间的 URI |
Throws | IllegalStateException: 如果当前状态不允许 Namespace 写入 |
Throws | XMLStreamException: |
writeDefaultNamespace
void writeDefaultNamespace(String namespaceURI) throws XMLStreamException
- Writes the default namespace to the stream
- Parameters:
namespaceURI
- the uri to bind the default namespace to- Throws:
IllegalStateException
- if the current state does not allow Namespace writingXMLStreamException
public void
writeComment(String data) throws XMLStreamException
编写一个包含数据的 XML 注释
data | 包含在注释中的数据,可以为 null |
Throws | XMLStreamException: |
writeComment
void writeComment(String data) throws XMLStreamException
- Writes an xml comment with the data enclosed
- Parameters:
data
- the data contained in the comment, may be null- Throws:
XMLStreamException
public void
writeProcessingInstruction(String target) throws XMLStreamException
编写一条处理指令
target | 处理指令的目标,不可以为 null |
Throws | XMLStreamException: |
writeProcessingInstruction
void writeProcessingInstruction(String target) throws XMLStreamException
- Writes a processing instruction
- Parameters:
target
- the target of the processing instruction, may not be null- Throws:
XMLStreamException
public void
writeProcessingInstruction(String target, String data) throws XMLStreamException
编写一条处理指令
target | 处理指令的目标,不可以为 null |
data | 处理指令中包含的数据,不可以为 null |
Throws | XMLStreamException: |
writeProcessingInstruction
void writeProcessingInstruction(String target, String data) throws XMLStreamException
- Writes a processing instruction
- Parameters:
target
- the target of the processing instruction, may not be nulldata
- the data contained in the processing instruction, may not be null- Throws:
XMLStreamException
public void
writeCData(String data) throws XMLStreamException
编写 CData 节
data | CData 节中包含的数据,不可以为 null |
Throws | XMLStreamException: |
writeCData
void writeCData(String data) throws XMLStreamException
- Writes a CData section
- Parameters:
data
- the data contained in the CData Section, may not be null- Throws:
XMLStreamException
public void
writeDTD(String dtd) throws XMLStreamException
编写 DTD 节。此字符串代表 XML 1.0 规范的整个 doctypedecl 产品。
dtd | 要编写的 DTD |
Throws | XMLStreamException: |
writeDTD
void writeDTD(String dtd) throws XMLStreamException
- Write a DTD section. This string represents the entire doctypedecl production
from the XML 1.0 specification.
- Parameters:
dtd
- the DTD to be written- Throws:
XMLStreamException
public void
writeEntityRef(String name) throws XMLStreamException
编写一个实体引用
name | 实体的名称 |
Throws | XMLStreamException: |
writeEntityRef
void writeEntityRef(String name) throws XMLStreamException
- Writes an entity reference
- Parameters:
name
- the name of the entity- Throws:
XMLStreamException
public void
writeStartDocument() throws XMLStreamException
编写 XML 声明。默认 XML 版本为 1.0,默认编码为 utf-8
Throws | XMLStreamException: |
writeStartDocument
void writeStartDocument() throws XMLStreamException
- Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8
- Throws:
XMLStreamException
public void
writeStartDocument(String version) throws XMLStreamException
编写 XML 声明。默认 XML 版本为 1.0
version | XML 文档的版本 |
Throws | XMLStreamException: |
writeStartDocument
void writeStartDocument(String version) throws XMLStreamException
- Write the XML Declaration. Defaults the XML version to 1.0
- Parameters:
version
- version of the xml document- Throws:
XMLStreamException
public void
writeStartDocument(String encoding, String version) throws XMLStreamException
编写 XML 声明。注意,编码参数不能设置底层输出的实际编码。它必须在使用 XMLOutputFactory 创建 XMLStreamWriter 实例时进行设置
encoding | XML 声明的编码 |
version | XML 文档的版本 |
Throws | XMLStreamException: |
writeStartDocument
void writeStartDocument(String encoding, String version) throws XMLStreamException
- Write the XML Declaration. Note that the encoding parameter does
not set the actual encoding of the underlying output. That must
be set when the instance of the XMLStreamWriter is created using the
XMLOutputFactory
- Parameters:
encoding
- encoding of the xml declarationversion
- version of the xml document- Throws:
XMLStreamException
public void
writeCharacters(String text) throws XMLStreamException
向输出写入文本
text | 要写入的值 |
Throws | XMLStreamException: |
writeCharacters
void writeCharacters(String text) throws XMLStreamException
- Write text to the output
- Parameters:
text
- the value to write- Throws:
XMLStreamException
public void
writeCharacters(char[] text, int start, int len) throws XMLStreamException
向输出写入文本
text | 要写入的值 |
start | 数组中的起始位置 |
len | 要写入的字符数 |
Throws | XMLStreamException: |
writeCharacters
void writeCharacters(char[] text, int start, int len) throws XMLStreamException
- Write text to the output
- Parameters:
text
- the value to writestart
- the starting position in the arraylen
- the number of characters to write- Throws:
XMLStreamException
public String
getPrefix(String uri) throws XMLStreamException
获取绑定 URI 的前缀
return | 前缀或 null |
Throws | XMLStreamException: |
getPrefix
String getPrefix(String uri) throws XMLStreamException
- Gets the prefix the uri is bound to
- Returns:
- the prefix or null
- Throws:
XMLStreamException
public void
setPrefix(String prefix, String uri) throws XMLStreamException
设置绑定 URI 的前缀。前缀在当前 START_ELEMENT / END_ELEMENT 对的范围内绑定。如果在写入 START_ELEMENT 之前调用此方法,则前缀在根范围内绑定。
prefix | 要绑定到 URI 的前缀,不可以为 null |
uri | 要绑定到前缀的 URI,不可以为 null |
Throws | XMLStreamException: |
setPrefix
void setPrefix(String prefix, String uri) throws XMLStreamException
- Sets the prefix the uri is bound to. This prefix is bound
in the scope of the current START_ELEMENT / END_ELEMENT pair.
If this method is called before a START_ELEMENT has been written
the prefix is bound in the root scope.
- Parameters:
prefix
- the prefix to bind to the uri, may not be nulluri
- the uri to bind to the prefix, may be null- Throws:
XMLStreamException
public void
setDefaultNamespace(String uri) throws XMLStreamException
将 URI 绑定到默认名称空间。此 URI 在当前 START_ELEMENT / END_ELEMENT 对的范围内绑定。如果在写入 START_ELEMENT 之前调用此方法,则 URI 在根范围内绑定。
uri | 要绑定到默认名称空间的 URI,不可以为 null |
Throws | XMLStreamException: |
setDefaultNamespace
void setDefaultNamespace(String uri) throws XMLStreamException
- Binds a URI to the default namespace
This URI is bound
in the scope of the current START_ELEMENT / END_ELEMENT pair.
If this method is called before a START_ELEMENT has been written
the uri is bound in the root scope.
- Parameters:
uri
- the uri to bind to the default namespace, may be null- Throws:
XMLStreamException
public void
setNamespaceContext(javax.xml.namespace.NamespaceContext context) throws XMLStreamException
设置前缀和 URI 绑定的当前名称空间上下文。此上下文成为用于写入的根名称空间上下文,并将替换当前的根名称空间上下文。通过将传递到此方法的上下文用作解析名称空间的根上下文,对 setPrefix 和 setDefaultNamespace 的后续调用将绑定名称空间。此方法只能在文档开始处调用一次。这不会导致名称空间被声明。如果在名称空间上下文中存在前缀映射关系的名称空间 URI,则它将被视为已经声明,并且该前缀可以被 StreamWriter 使用。
context | 将用于此 writer 的名称空间上下文,不可以为 null |
Throws | XMLStreamException: |
setNamespaceContext
void setNamespaceContext(NamespaceContext context) throws XMLStreamException
- Sets the current namespace context for prefix and uri bindings.
This context becomes the root namespace context for writing and
will replace the current root namespace context. Subsequent calls
to setPrefix and setDefaultNamespace will bind namespaces using
the context passed to the method as the root context for resolving
namespaces. This method may only be called once at the start of
the document. It does not cause the namespaces to be declared.
If a namespace URI to prefix mapping is found in the namespace
context it is treated as declared and the prefix may be used
by the StreamWriter.
- Parameters:
context
- the namespace context to use for this writer, may not be null- Throws:
XMLStreamException
public javax.xml.namespace.NamespaceContext
getNamespaceContext()
返回当前名称空间上下文。
return | 当前 NamespaceContext |
getNamespaceContext
NamespaceContext getNamespaceContext()
- Returns the current namespace context.
- Returns:
- the current NamespaceContext
public Object
getProperty(String name) throws IllegalArgumentException
从底层实现获取功能/属性的值。
name | 属性的名称,不可以为 null |
return | 属性的值 |
Throws | IllegalArgumentException: 如果属性不受支持 |
Throws | NullPointerException: 如果名称为 null。 |
getProperty
Object getProperty(String name) throws IllegalArgumentException
- Get the value of a feature/property from the underlying implementation
- Parameters:
name
- The name of the property, may not be null- Returns:
- The value of the property
- Throws:
IllegalArgumentException
- if the property is not supportedNullPointerException
- if the name is null
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!