Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bluk/maybe_xml
A non-validating XML pull parser.
https://github.com/bluk/maybe_xml
parser pull-parser rust xml xml-parser
Last synced: about 2 months ago
JSON representation
A non-validating XML pull parser.
- Host: GitHub
- URL: https://github.com/bluk/maybe_xml
- Owner: bluk
- License: apache-2.0
- Created: 2020-08-24T17:09:54.000Z (over 4 years ago)
- Default Branch: trunk
- Last Pushed: 2024-05-02T16:31:08.000Z (9 months ago)
- Last Synced: 2024-12-10T10:28:49.658Z (2 months ago)
- Topics: parser, pull-parser, rust, xml, xml-parser
- Language: Rust
- Homepage: https://docs.rs/maybe_xml/
- Size: 7.82 MB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# MaybeXml
MaybeXml is a library to scan and evaluate [XML][xml]-like data into tokens. In
effect, the library provides a non-validating parser. The interface is similar to
many XML pull parsers.* [Latest API Documentation][api_docs]
## Purpose
The purpose of the library is to provide a way to read XML documents including
office suite documents, RSS/Atom feeds, config files, SVG, and web service
messages.## Examples
### Using `tokenize()`
```rust
use maybe_xml::{Reader, token::{Characters, EndTag, StartTag, Ty}};let input = "123";
let reader = Reader::from_str(input);
let mut pos = 0;let token = reader.tokenize(&mut pos);
if let Some(Ty::StartTag(tag)) = token.map(|t| t.ty()) {
assert_eq!("id", tag.name().local().as_str());
assert_eq!(None, tag.name().namespace_prefix());
} else {
panic!();
}
assert_eq!(4, pos);let token = reader.tokenize(&mut pos);
if let Some(Ty::Characters(chars)) = token.map(|t| t.ty()) {
assert_eq!("123", chars.content().as_str());
} else {
panic!();
}
assert_eq!(7, pos);let token = reader.tokenize(&mut pos);
if let Some(Ty::EndTag(tag)) = token.map(|t| t.ty()) {
assert_eq!("", tag.as_str());
assert_eq!("id", tag.name().local().as_str());
} else {
panic!();
}
assert_eq!(12, pos);let token = reader.tokenize(&mut pos);
assert_eq!(None, token);// Verify that `pos` is equal to `input.len()` to ensure all data was
// processed.
```### Using `Iterator` functionality
```rust
use maybe_xml::{Reader, token::Ty};let input = "123Jane Doe";
let reader = Reader::from_str(input);
let mut iter = reader.into_iter().filter_map(|token| {
match token.ty() {
Ty::StartTag(tag) => Some(tag.name().as_str()),
_ => None,
}
});let name = iter.next();
assert_eq!(Some("id"), name);let name = iter.next();
assert_eq!(Some("name"), name);assert_eq!(None, iter.next());
```## Installation
```sh
cargo add maybe_xml
```By default, the `std` feature is enabled.
### Alloc only
If the host environment has an allocator but does not have access to the Rust
`std` library:```sh
cargo add --no-default-features --features alloc maybe_xml
```### No allocator / core only
If the host environment does not have an allocator:
```sh
cargo add --no-default-features maybe_xml
```## License
Licensed under either of [Apache License, Version 2.0][LICENSE_APACHE] or [MIT
License][LICENSE_MIT] at your option.### Contributions
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.[LICENSE_APACHE]: LICENSE-APACHE
[LICENSE_MIT]: LICENSE-MIT
[xml]: https://www.w3.org/TR/2006/REC-xml11-20060816/
[api_docs]: https://docs.rs/maybe_xml/