Crate rxml

source · []
Expand description

Restricted XML parsing and encoding

This crate provides “restricted” parsing and encoding of XML 1.0 documents with namespacing.

Features (some call them restrictions)

  • No external resources
  • No custom entities
  • No DTD whatsoever
  • No processing instructions
  • No comments
  • UTF-8 only
  • Namespacing-well-formedness enforced
  • XML 1.0 only
  • Streamed parsing (parser emits a subset of SAX events)
  • Streamed encoding
  • Parser can be driven push- and pull-based
  • Tokio-based asynchronicity supported via the async feature and AsyncParser.

Example

use rxml::EventRead;
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = rxml::FeedParser::new();
fp.feed(doc.to_vec());
fp.feed_eof();
let result = fp.read_all_eof(|ev| {
	println!("got event: {:?}", ev);
});
// true indicates eof
assert_eq!(result.unwrap(), true);

High-level parser usage

Push-based usage

The FeedParser allows to push bits of XML into the parser as they arrive in the application and process the resulting Events as they happen.

Pull-based usage

If the parser should block while waiting for more data to arrive, a PullParser can be used instead. The PullParser requires a source which implements io::BufRead.

Usage with Tokio

Tokio is supported with the async feature. It offers the AsyncParser and the AsyncEventRead trait, which work similar to the PullParser. Instead of blocking, however, the async parser will yield control to other tasks.

Re-exports

pub use strings::CData;
pub use strings::CDataStr;
pub use strings::NCName;
pub use strings::NCNameStr;
pub use strings::Name;
pub use strings::NameStr;

Modules

Error types

XML 1.0 Lexer

XML 1.0 Parser

Strongly-typed strings for use with XML 1.0 documents

Writer for restricted XML 1.0

Structs

Tokio-compatible asynchronous parser

Zero-copy buffered reader for a queue of byte slices.

Shared context for multiple parsers

Encodes XML into buffers.

Non-blocking parsing

Restricted XML 1.0 lexer

Wrapper around Lexer and std::io::BufRead to provide a TokenRead.

Hold options to configure a Lexer.

Low-level XML Parser

Blocking parsing

Enums

Error types which may be returned from the parser or lexer.

XML document parts

An encodable item.

XML version number

Constants

Package version

XML core namespace URI (for the xml: prefix)

Traits

Asynchronous source of individual XML events

Helper trait for asynchronous sources of individual XML events

Source for individual XML events

Functions

Convert end-of-file-ness of a result to a boolean flag.

Type Definitions