#xml #parser #tokenizer

no-std xmlparser

Pull-based, zero-allocation XML parser

23 releases (12 breaking)

0.13.6 Sep 30, 2023
0.13.5 Oct 18, 2022
0.13.4 Jun 24, 2021
0.13.3 Sep 2, 2020
0.1.0 Dec 15, 2017

#29 in Parser implementations

Download history 238271/week @ 2024-01-03 248630/week @ 2024-01-10 273916/week @ 2024-01-17 269957/week @ 2024-01-24 254864/week @ 2024-01-31 250666/week @ 2024-02-07 250943/week @ 2024-02-14 266515/week @ 2024-02-21 281173/week @ 2024-02-28 277006/week @ 2024-03-06 280292/week @ 2024-03-13 269297/week @ 2024-03-20 263863/week @ 2024-03-27 296645/week @ 2024-04-03 295722/week @ 2024-04-10 253605/week @ 2024-04-17

1,160,538 downloads per month
Used in 1,241 crates (30 directly)

MIT/Apache

69KB
1.5K SLoC

xmlparser

Build Status Crates.io Documentation Rust 1.31+

xmlparser is a low-level, pull-based, zero-allocation XML 1.0 parser.

Example

for token in xmlparser::Tokenizer::from("<tagname name='value'/>") {
    println!("{:?}", token);
}

Why a new library?

This library is basically a low-level XML tokenizer that preserves the positions of the tokens and is not intended to be used directly. If you are looking for a higher level solution, check out roxmltree.

Benefits

  • All tokens contain StrSpan structs which represent the position of the substring in the original document.
  • Good error processing. All error types contain the position (line:column) where it occurred.
  • No heap allocations.
  • No dependencies.
  • Tiny. ~1400 LOC and ~30KiB in the release build according to cargo-bloat.
  • Supports no_std builds. To use without the standard library, disable the default features.

Limitations

  • Currently, only ENTITY objects are parsed from the DOCTYPE. All others are ignored.
  • No tree structure validation. So an XML like <root><child></root></child> or a string without root element will be parsed without errors. You should check for this manually. On the other hand <a/><a/> will lead to an error.
  • Duplicated attributes is not an error. So XML like <item a="v1" a="v2"/> will be parsed without errors. You should check for this manually.
  • UTF-8 only.

Safety

  • The library must not panic. Any panic is considered a critical bug and should be reported.
  • The library forbids unsafe code.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features