XML
XML’s rules, not HTML’s recovery. A well-formedness error stops the parse, a name is its namespace and local part, and entities expand only as far as you allow.
What it does
- XML 1.0 (Fifth Edition) and Namespaces in XML 1.0, not validating, with its own tokenizer and tree.
- A span on every node, and errors with a line and column.
- Bytes in, decoded as XML says: from the byte order mark and the XML declaration.
- XPath 1.0 over the tree, behind the
xpathfeature. - Writing the document back out.
- Limits on depth, entity nesting and entity expansion, so a billion laughs stops in milliseconds.
Add it
In Rust, add parsec-xml (0.3.1 on crates.io); the library inside isparsec_xml. Parsing works from Python, JavaScript and C as well. XPath over XML is Rust only for now.
let feed = r#"<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<entry><title>Ships & ports</title></entry>
</feed>"#;
let doc = parsec_xml::parse(feed).unwrap();
let root = doc.root_element();
let name = doc.name(root).unwrap();
assert_eq!((name.local, name.namespace), ("feed", "http://www.w3.org/2005/Atom"));
assert_eq!(doc.xml_lang(root), Some("en"));
assert_eq!(doc.text(root).trim(), "Ships & ports");That's the first example in the crate's own documentation at the v0.3.1 tag, unchanged.cargo test runs it on every change, so it compiles and passes against the release you'd install. The API reference on docs.rs has the rest, and the getting started guide goes step by step.
Checked against the standards
These counts are the conformance baseline on Parsec's main branch, read when this page was built. Each release has to match or beat them: a suite that passes fewer cases, or fails more, stops the release.
| Suite | Pass | Fail | Skipped |
|---|---|---|---|
| W3C XML conformance | 1,915 | 0 | 670 |
| libxml2 XPath over documents | 84 | 0 | 0 |
Standards has every suite, where its data comes from, and why the failures and skips are what they are.
Where it stops
- It doesn’t validate against a DTD or a schema.
- It never fetches a URL or opens a file. External DTDs and entities are left unread, and it tells you which ones.
The XML page in the docs goes through the API, the limits and the conformance details in full.