Crates.io | xml5ever |
lib.rs | xml5ever |
version | 0.20.0 |
source | src |
created_at | 2015-11-30 16:42:58.55625 |
updated_at | 2024-09-11 16:22:07.287235 |
description | Push based streaming parser for XML. |
homepage | https://github.com/servo/html5ever/blob/main/xml5ever/README.md |
repository | https://github.com/servo/html5ever |
max_upload_size | |
id | 3553 |
size | 172,803 |
Warning: This library is alpha quality, so no guarantees are given.
This crate provides a push based XML parser library that trades well-formedness for error recovery.
xml5ever is based largely on html5ever parser, so if you have experience with html5ever you will be familiar with xml5ever.
The library is dual licensed under MIT and Apache license.
Main use case for this library is when XML is badly formatted, usually from bad XML templates. XML5 tries to handle most common errors, in a manner similar to HTML5.
Add xml5ever as a dependency in your project manifest:
[dependencies]
xml5ever = "0.18"
Here is a very simple RcDom backed parser:
let input = "<xml></xml>".to_tendril();
// To parse XML into a tree form, we need a TreeSink
// luckily xml5ever comes with a static RC backed tree represetation.
let dom: RcDom = parse(std::iter::once(input), Default::default());
// Do something with dom
The thing that does actual parsing is the parse
function. It expects an iterator that can be converted into StrTendril
, so you can use std::iter::once(input)
or Some(input).into_iter()
(where input
is StrTendril
like structure).
To build examples and tests you need to do something along the lines of:
git submodule update --init # to fetch xml5lib-tests
cargo build
cargo test
This will fetch tests from outside repository and it will invoke cargo to
build and test the crate. If you need docs checkout either API docs or run cargo docs
to generate documentation.