//! Contains high-level interface for a pull-based XML parser. //! //! The most important type in this module is `EventReader`, which provides an iterator //! view for events in XML document.
/// A result type yielded by `XmlReader`. pubtype Result<T> = result::Result<T, Error>;
/// A wrapper around an `std::io::Read` instance which provides pull-based XML parsing. pubstruct EventReader<R: Read> {
source: R,
parser: PullParser
}
impl<R: Read> EventReader<R> { /// Creates a new reader, consuming the given stream. #[inline] pubfn new(source: R) -> EventReader<R> {
EventReader::new_with_config(source, ParserConfig::new())
}
/// Creates a new reader with the provded configuration, consuming the given stream. #[inline] pubfn new_with_config(source: R, config: ParserConfig) -> EventReader<R> {
EventReader { source: source, parser: PullParser::new(config) }
}
/// Pulls and returns next XML event from the stream. /// /// If returned event is `XmlEvent::Error` or `XmlEvent::EndDocument`, then /// further calls to this method will return this event again. #[inline] pubfn next(&mutself) -> Result<XmlEvent> { self.parser.next(&mutself.source)
}
/// Unwraps this `EventReader`, returning the underlying reader. /// /// Note that this operation is destructive; unwrapping the reader and wrapping it /// again with `EventReader::new()` will create a fresh reader which will attempt /// to parse an XML document from the beginning. pubfn into_inner(self) -> R { self.source
}
}
impl<B: Read> Position for EventReader<B> { /// Returns the position of the last event produced by the reader. #[inline] fn position(&self) -> TextPosition { self.parser.position()
}
}
impl<R: Read> IntoIterator for EventReader<R> { type Item = Result<XmlEvent>; type IntoIter = Events<R>;
/// An iterator over XML events created from some type implementing `Read`. /// /// When the next event is `xml::event::Error` or `xml::event::EndDocument`, then /// it will be returned by the iterator once, and then it will stop producing events. pubstruct Events<R: Read> {
reader: EventReader<R>,
finished: bool
}
impl<R: Read> Events<R> { /// Unwraps the iterator, returning the internal `EventReader`. #[inline] pubfn into_inner(self) -> EventReader<R> { self.reader
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.