Module  java.xml
软件包  javax.xml.stream

Interface XMLEventWriter

    • 方法摘要

      所有方法  接口方法  抽象方法 
      Modifier and Type 方法 描述
      void add​(XMLEvent event)
      将事件添加到输出流添加START_ELEMENT将打开一个新的命名空间范围,当对应的END_ELEMENT被写入时,它将被关闭。
      void add​(XMLEventReader reader)
      将一个整个流添加到输出流,在inputStream参数上调用next(),直到hasNext()返回false这应被视为一种方便的方法,它将对事件读取器中的所有事件执行以下循环,并在每个事件中调用add事件。
      void close​()
      释放与此流相关联的任何资源
      void flush​()
      将任何缓存的事件写入基础输出机制
      NamespaceContext getNamespaceContext​()
      返回当前的命名空间上下文。
      String getPrefix​(String uri)
      获取uri绑定的前缀
      void setDefaultNamespace​(String uri)
      将URI绑定到默认命名空间此URI绑定在当前START_ELEMENT / END_ELEMENT对的范围内。
      void setNamespaceContext​(NamespaceContext context)
      设置前缀和uri绑定的当前命名空间上下文。
      void setPrefix​(String prefix, String uri)
      设置uri所绑定的前缀。
    • 方法详细信息

      • add

        void add​(XMLEvent event)
          throws XMLStreamException
        将事件添加到输出流添加START_ELEMENT将打开一个新的命名空间范围,当对应的END_ELEMENT被写入时,它将被关闭。 Required and optional fields for events added to the writer Event Type Required Fields Optional Fields Required Behavior START_ELEMENT QName name namespaces , attributes A START_ELEMENT will be written by writing the name, namespaces, and attributes of the event in XML 1.0 valid syntax for START_ELEMENTs. The name is written by looking up the prefix for the namespace uri. The writer can be configured to respect prefixes of QNames. If the writer is respecting prefixes it must use the prefix set on the QName. The default behavior is to lookup the value for the prefix on the EventWriter's internal namespace context. Each attribute (if any) is written using the behavior specified in the attribute section of this table. Each namespace (if any) is written using the behavior specified in the namespace section of this table. END_ELEMENT Qname name None A well formed END_ELEMENT tag is written. The name is written by looking up the prefix for the namespace uri. The writer can be configured to respect prefixes of QNames. If the writer is respecting prefixes it must use the prefix set on the QName. The default behavior is to lookup the value for the prefix on the EventWriter's internal namespace context. If the END_ELEMENT name does not match the START_ELEMENT name an XMLStreamException is thrown. ATTRIBUTE QName name , String value QName type An attribute is written using the same algorithm to find the lexical form as used in START_ELEMENT. The default is to use double quotes to wrap attribute values and to escape any double quotes found in the value. The type value is ignored. NAMESPACE String prefix, String namespaceURI, boolean isDefaultNamespaceDeclaration None A namespace declaration is written. If the namespace is a default namespace declaration (isDefault is true) then xmlns="$namespaceURI" is written and the prefix is optional. If isDefault is false, the prefix must be declared and the writer must prepend xmlns to the prefix and write out a standard prefix declaration. PROCESSING_INSTRUCTION None String target, String data The data does not need to be present and may be null. Target is required and many not be null. The writer will write data section directly after the target, enclosed in appropriate XML 1.0 syntax COMMENT None String comment If the comment is present (not null) it is written, otherwise an an empty comment is written START_DOCUMENT None String encoding , boolean standalone, String version A START_DOCUMENT event is not required to be written to the stream. If present the attributes are written inside the appropriate XML declaration syntax END_DOCUMENT None None Nothing is written to the output DTD String DocumentTypeDefinition None The DocumentTypeDefinition is written to the output
        Specified by:
        add在接口 XMLEventConsumer
        参数
        event - 要添加的事件
        异常
        XMLStreamException
      • add

        void add​(XMLEventReader reader)
          throws XMLStreamException
        将一个整个流添加到输出流,在inputStream参数上调用next(),直到hasNext()返回false这应被视为一种方便的方法,它将对事件读取器中的所有事件执行以下循环,并在每个事件中调用add事件。
        参数
        reader - 事件流添加到输出
        异常
        XMLStreamException
      • setPrefix

        void setPrefix​(String prefix,
                       String uri)
                throws XMLStreamException
        设置uri所绑定的前缀。 此前缀绑定在当前START_ELEMENT / END_ELEMENT对的范围内。 如果在编写START_ELEMENT之前调用此方法,则前缀将绑定到根目录中。
        参数
        prefix - 绑定到uri的前缀
        uri - 绑定到前缀的uri
        异常
        XMLStreamException
      • setDefaultNamespace

        void setDefaultNamespace​(String uri)
                          throws XMLStreamException
        将URI绑定到默认命名空间此URI绑定在当前START_ELEMENT / END_ELEMENT对的范围内。 如果在写入START_ELEMENT之前调用此方法,则uri将绑定到根范围中。
        参数
        uri - 绑定到默认命名空间的uri
        异常
        XMLStreamException
      • setNamespaceContext

        void setNamespaceContext​(NamespaceContext context)
                          throws XMLStreamException
        设置前缀和uri绑定的当前命名空间上下文。 此上下文成为写入的根命名空间上下文,并将替换当前根命名空间上下文。 对setPrefix和setDefaultNamespace的后续调用将使用传递给方法的上下文作为解析命名空间的根上下文来绑定命名空间。
        参数
        context - 用于此作者的命名空间上下文
        异常
        XMLStreamException
      • getNamespaceContext

        NamespaceContext getNamespaceContext​()
        返回当前的命名空间上下文。
        结果
        当前命名空间上下文