pub struct RawParser { /* private fields */ }Expand description
§Low-level restricted XML 1.0 parser (without namespace support)
This parser emits RawEvent items, which represent the logical structure
of the XML document before resolution of namespaces. If you want to use
namespaces and have them resolved fully, use Parser instead.
§Caveats
It is possible for an XML document to pass parsing using just this parser and still be not well-formed or namespace-well-formed. In particular, the following cases are not detected and must be handled by consumer code:
- Duplicate attributes
- Uses of undeclared prefixes
- Multiple attributes resolving to the same namespace URI / localpart pair after prefix expansion
See Parser for a full parser implementation which ensures well-formedness
and namespace-well-formedness.
§Example
use rxml::{RawParser, Parse, Error, RawEvent, XmlVersion};
use std::io;
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = RawParser::new();
// We expect a WouldBlock, because the XML declaration is not complete yet
assert!(matches!(
fp.parse(&mut &doc[..10], false).err().unwrap(),
Error::IO(e) if e.kind() == io::ErrorKind::WouldBlock
));
// 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(), RawEvent::XmlDeclaration(_, XmlVersion::V1_0)));Implementations§
Trait Implementations§
source§impl Parse for RawParser
impl Parse for RawParser
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>>
Parse a single event from the bytes in
buf. Read moresource§fn release_temporaries(&mut self)
fn release_temporaries(&mut self)
Release all temporary buffers or other ephemeral allocations Read more
source§fn parse_all<F: FnMut(Self::Output)>(
&mut self,
data: &mut &[u8],
at_eof: bool,
f: F,
) -> Result<()>
fn parse_all<F: FnMut(Self::Output)>( &mut self, data: &mut &[u8], at_eof: bool, f: F, ) -> Result<()>
Parse all data from the given buffer and pass the generated events to
a callback. Read more
source§impl WithOptions for RawParser
impl WithOptions for RawParser
source§fn with_options(options: Options) -> Self
fn with_options(options: Options) -> Self
Create a new instance using the given options.
Auto Trait Implementations§
impl Freeze for RawParser
impl !RefUnwindSafe for RawParser
impl Send for RawParser
impl Sync for RawParser
impl Unpin for RawParser
impl !UnwindSafe for RawParser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> WithContext for Twhere
T: WithOptions,
impl<T> WithContext for Twhere
T: WithOptions,
source§fn with_context(ctx: Arc<Context>) -> T
fn with_context(ctx: Arc<Context>) -> T
👎Deprecated since 0.10.0: use WithOptions::with_options
Create an object with the given parsing context.