pub struct Parser { /* private fields */ }
Expand description
§Non-blocking restricted XML 1.0 parser
The Parser
allows parsing XML documents as they arrive in the application,
giving back control to the caller immediately when not enough data is available
for processing. This is especially useful when streaming data from sockets.
To read events from the Parser
after feeding data, use its Parse
trait.
§Example
use rxml::{Parser, Parse, Error, Event, XmlVersion, error::EndOrError};
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = Parser::new();
// We expect a NeedMoreData, because the XML declaration is not complete yet
assert!(matches!(
fp.parse(&mut &doc[..10], false).err().unwrap(),
EndOrError::NeedMoreData,
));
// Now we pass the XML declaration (and some), so we expect a corresponding
// event
let ev = fp.parse(&mut &doc[10..25], false);
assert!(matches!(ev.unwrap().unwrap(), Event::XmlDeclaration(_, XmlVersion::V1_0)));
In contrast to a RawParser
, the Parser
enforces well-formedness and
namespace-well-formedness.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn set_text_buffering(&mut self, enabled: bool)
pub fn set_text_buffering(&mut self, enabled: bool)
Configure text buffering (enabled by default).
If enabled, text content is buffered up to the configured token size limit, unless it is more efficient to flush it out anyway.
If disabled, text content is emitted as event as soon as at least one valid char has been read.
Enabling text buffering reduces the number of calls which need to be made into the parser and thus may improve performance. However, it also makes the application see the text content later, which may be problematic if control flow which affects parsing depends on text content.
Sourcepub fn text_buffering(&self) -> bool
pub fn text_buffering(&self) -> bool
Return whether text buffering is enabled.
See set_text_buffering
.
Trait Implementations§
Source§impl Parse for Parser
impl Parse for Parser
Source§fn parse(&mut self, r: &mut &[u8], at_eof: bool) -> Result<Option<Self::Output>>
fn parse(&mut self, r: &mut &[u8], at_eof: bool) -> Result<Option<Self::Output>>
buf
. Read more