pub struct EventReader<R: Read> { /* private fields */ }Expand description
A wrapper around an std::io::Read instance which provides pull-based XML parsing.
The reader should be wrapped in a BufReader, otherwise parsing may be very slow.
Implementations§
Source§impl<R: Read> EventReader<R>
impl<R: Read> EventReader<R>
Sourcepub fn new(source: R) -> Self
pub fn new(source: R) -> Self
Creates a new reader, consuming the given stream. The reader should be wrapped in a BufReader, otherwise parsing may be very slow.
Sourcepub fn new_with_config(source: R, config: impl Into<ParserConfig>) -> Self
pub fn new_with_config(source: R, config: impl Into<ParserConfig>) -> Self
Creates a new reader with the provded configuration, consuming the given stream. The reader should be wrapped in a BufReader, otherwise parsing may be very slow.
Sourcepub fn next(&mut self) -> Result<XmlEvent>
pub fn next(&mut self) -> Result<XmlEvent>
Pulls and returns next XML event from the stream.
If this returns Err or XmlEvent::EndDocument then further calls to
this method will return this event again.
Sourcepub fn skip(&mut self) -> Result<()>
pub fn skip(&mut self) -> Result<()>
Skips all XML events until the next end tag at the current level.
Convenience function that is useful for the case where you have encountered a start tag that is of no interest and want to skip the entire XML subtree until the corresponding end tag.
Sourcepub fn source(&self) -> &R
pub fn source(&self) -> &R
Access underlying reader
Using it directly while the event reader is parsing is not recommended
Sourcepub fn source_mut(&mut self) -> &mut R
pub fn source_mut(&mut self) -> &mut R
Access underlying reader
Using it directly while the event reader is parsing is not recommended
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
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.
Sourcepub fn doctype(&self) -> Option<&str>
👎Deprecated: there is XmlEvent::Doctype now
pub fn doctype(&self) -> Option<&str>
XmlEvent::Doctype nowReturns the DOCTYPE of the document if it has already been seen
Available only after the root StartElement event
Sourcepub fn add_entities<S: Into<String>, T: Into<String>>(
&mut self,
entities: impl IntoIterator<Item = (S, T)>,
) -> Result<(), ImmutableEntitiesError>
pub fn add_entities<S: Into<String>, T: Into<String>>( &mut self, entities: impl IntoIterator<Item = (S, T)>, ) -> Result<(), ImmutableEntitiesError>
Add new entity definitions before any XML elements have been parsed.
§Errors
It’s valid to call this after DOCTYPE, but not later. It won’t be possible to add entities to a document without either XML decl or DOCTYPE.
It will fail if the document is declared as standalone.
Trait Implementations§
Source§impl<R: Read> IntoIterator for EventReader<R>
impl<R: Read> IntoIterator for EventReader<R>
Source§impl<B: Read> Position for EventReader<B>
impl<B: Read> Position for EventReader<B>
Source§fn position(&self) -> TextPosition
fn position(&self) -> TextPosition
Returns the position of the last event produced by the reader.