Enum xml::writer::events::XmlEvent [] [src]

pub enum XmlEvent<'a> {
    StartDocument {
        version: XmlVersion,
        encoding: Option<&'a str>,
        standalone: Option<bool>,
    },
    ProcessingInstruction {
        name: &'a str,
        data: Option<&'a str>,
    },
    StartElement {
        name: Name<'a>,
        attributes: Cow<'a, [Attribute<'a>]>,
        namespace: Cow<'a, Namespace>,
    },
    EndElement {
        name: Option<Name<'a>>,
    },
    CData(&'a str),
    Comment(&'a str),
    Characters(&'a str),
}

A part of an XML output stream.

Objects of this enum are consumed by EventWriter. They correspond to different parts of an XML document.

Variants

StartDocument

Corresponds to XML document declaration.

This event should always be written before any other event. If it is not written at all, a default XML declaration will be outputted if the corresponding option is set in the configuration. Otherwise an error will be returned.

Fields

version

XML version.

Defaults to XmlVersion::Version10.

encoding

XML document encoding.

Defaults to Some("UTF-8").

standalone

XML standalone declaration.

Defaults to None.

ProcessingInstruction

Denotes an XML processing instruction.

Fields

name

Processing instruction target.

data

Processing instruction content.

StartElement

Denotes a beginning of an XML element.

Fields

name

Qualified name of the element.

attributes

A list of attributes associated with the element.

Currently attributes are not checked for duplicates (TODO). Attribute values will be escaped, and all characters invalid for attribute values like " or < will be changed into character entities.

namespace

Contents of the namespace mapping at this point of the document.

This mapping will be inspected for "new" entries, and if at this point of the document a particular pair of prefix and namespace URI is already defined, no namespace attributes will be emitted.

EndElement

Denotes an end of an XML element.

Fields

name

Optional qualified name of the element.

If None, then it is assumed that the element name should be the last valid one. If Some and element names tracking is enabled, then the writer will check it for correctness.

CData

Denotes CDATA content.

This event contains unparsed data, and no escaping will be performed when writing it to the output stream.

Comment

Denotes a comment.

The string will be checked for invalid sequences and error will be returned by the write operation

Characters

Denotes character data outside of tags.

Contents of this event will be escaped if perform_escaping option is enabled, that is, every character invalid for PCDATA will appear as a character entity.

Methods

impl<'a> XmlEvent<'a>
[src]

fn processing_instruction(name: &'a str, data: Option<&'a str>) -> XmlEvent<'a>

Returns an writer event for a processing instruction.

fn start_element<S>(name: S) -> StartElementBuilder<'a> where S: Into<Name<'a>>

Returns a builder for a starting element.

This builder can then be used to tweak attributes and namespace starting at this element.

fn end_element() -> EndElementBuilder<'a>

Returns a builder for an closing element.

This method, unline start_element(), does not accept a name because by default the writer is able to determine it automatically. However, when this functionality is disabled, it is possible to specify the name with name() method on the builder.

fn cdata(data: &'a str) -> XmlEvent<'a>

Returns a CDATA event.

Naturally, the provided string won't be escaped, except for closing CDATA token ]]> (depending on the configuration).

fn characters(data: &'a str) -> XmlEvent<'a>

Returns a regular characters (PCDATA) event.

All offending symbols, in particular, & and <, will be escaped by the writer.

fn comment(data: &'a str) -> XmlEvent<'a>

Returns a comment event.

Trait Implementations

impl<'a> From<&'a str> for XmlEvent<'a>
[src]

fn from(s: &'a str) -> XmlEvent<'a>

Performs the conversion.

impl<'a> From<EndElementBuilder<'a>> for XmlEvent<'a>
[src]

fn from(b: EndElementBuilder<'a>) -> XmlEvent<'a>

Performs the conversion.

impl<'a> From<StartElementBuilder<'a>> for XmlEvent<'a>
[src]

fn from(b: StartElementBuilder<'a>) -> XmlEvent<'a>

Performs the conversion.