pub enum XmlEvent {
StartDocument {
version: XmlVersion,
encoding: String,
standalone: Option<bool>,
},
EndDocument,
ProcessingInstruction {
name: String,
data: Option<String>,
},
StartElement {
name: OwnedName,
attributes: Vec<OwnedAttribute>,
namespace: Namespace,
},
EndElement {
name: OwnedName,
},
CData(String),
Comment(String),
Characters(String),
Whitespace(String),
}
Expand description
An element of an XML input stream.
Items of this enum are emitted by reader::EventReader
. They correspond to different
elements of an XML document.
Variants
StartDocument
Fields
version: XmlVersion
XML version.
If XML declaration is not present, defaults to Version10
.
encoding: String
XML document encoding.
If XML declaration is not present or does not contain encoding
attribute,
defaults to "UTF-8"
. This field is currently used for no other purpose than
informational.
Corresponds to XML document declaration.
This event is always emitted before any other event. It is emitted even if the actual declaration is not present in the document.
EndDocument
Denotes to the end of the document stream.
This event is always emitted after any other event (except Error
). After it
is emitted for the first time, it will always be emitted on next event pull attempts.
ProcessingInstruction
Fields
name: String
Processing instruction target.
Denotes an XML processing instruction.
This event contains a processing instruction target (name
) and opaque data
. It
is up to the application to process them.
StartElement
Fields
name: OwnedName
Qualified name of the element.
attributes: Vec<OwnedAttribute>
A list of attributes associated with the element.
Currently attributes are not checked for duplicates (TODO)
namespace: Namespace
Contents of the namespace mapping at this point of the document.
Denotes a beginning of an XML element.
This event is emitted after parsing opening tags or after parsing bodiless tags. In the
latter case EndElement
event immediately follows.
EndElement
Fields
name: OwnedName
Qualified name of the element.
Denotes an end of an XML element.
This event is emitted after parsing closing tags or after parsing bodiless tags. In the
latter case it is emitted immediately after corresponding StartElement
event.
CData(String)
Denotes CDATA content.
This event contains unparsed data. No unescaping will be performed.
It is possible to configure a parser to emit Characters
event instead of CData
. See
pull::ParserConfiguration
structure for more information.
Comment(String)
Denotes a comment.
It is possible to configure a parser to ignore comments, so this event will never be emitted.
See pull::ParserConfiguration
structure for more information.
Characters(String)
Denotes character data outside of tags.
Contents of this event will always be unescaped, so no entities like <
or &
or {
will appear in it.
It is possible to configure a parser to trim leading and trailing whitespace for this event.
See pull::ParserConfiguration
structure for more information.
Whitespace(String)
Denotes a chunk of whitespace outside of tags.
It is possible to configure a parser to emit Characters
event instead of Whitespace
.
See pull::ParserConfiguration
structure for more information. When combined with whitespace
trimming, it will eliminate standalone whitespace from the event stream completely.
Implementations
sourceimpl XmlEvent
impl XmlEvent
sourcepub fn as_writer_event<'a>(&'a self) -> Option<XmlEvent<'a>>
pub fn as_writer_event<'a>(&'a self) -> Option<XmlEvent<'a>>
Obtains a writer event from this reader event.
This method is useful for streaming processing of XML documents where the output is also an XML document. With this method it is possible to process some events while passing other events through to the writer unchanged:
use std::str;
use xml::{EventReader, EventWriter};
use xml::reader::XmlEvent as ReaderEvent;
use xml::writer::XmlEvent as WriterEvent;
let mut input: &[u8] = b"<hello>world</hello>";
let mut output: Vec<u8> = Vec::new();
{
let mut reader = EventReader::new(&mut input);
let mut writer = EventWriter::new(&mut output);
for e in reader {
match e.unwrap() {
ReaderEvent::Characters(s) =>
writer.write(WriterEvent::characters(&s.to_uppercase())).unwrap(),
e => if let Some(e) = e.as_writer_event() {
writer.write(e).unwrap()
}
}
}
}
assert_eq!(
str::from_utf8(&output).unwrap(),
r#"<?xml version="1.0" encoding="UTF-8"?><hello>WORLD</hello>"#
);
Note that this API may change or get additions in future to improve its ergonomics.
Trait Implementations
impl StructuralPartialEq for XmlEvent
Auto Trait Implementations
impl RefUnwindSafe for XmlEvent
impl Send for XmlEvent
impl Sync for XmlEvent
impl Unpin for XmlEvent
impl UnwindSafe for XmlEvent
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more