Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Florob/RustyXML
A XML parser written in Rust
https://github.com/Florob/RustyXML
Last synced: 3 months ago
JSON representation
A XML parser written in Rust
- Host: GitHub
- URL: https://github.com/Florob/RustyXML
- Owner: Florob
- License: apache-2.0
- Created: 2013-07-28T16:39:00.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-09-05T09:19:22.000Z (over 3 years ago)
- Last Synced: 2024-09-20T02:09:22.325Z (4 months ago)
- Language: Rust
- Size: 297 KB
- Stars: 103
- Watchers: 7
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-rust-cn - Florob/RustyXML - ci.org/Florob/RustyXML.svg?branch=master">](https://travis-ci.org/Florob/RustyXML) (Libraries / Encoding)
- awesome-rust - Florob/RustyXML - ci.org/Florob/RustyXML.svg?branch=master">](https://travis-ci.org/Florob/RustyXML) (Libraries / Encoding)
- awesome-rust - Florob/RustyXML - ci.org/Florob/RustyXML.svg?branch=master">](https://travis-ci.org/Florob/RustyXM) (代码 / 编码)
- awesome-rust - Florob/RustyXML
- awesome-rust-cn - Florob/RustyXML
- awesome-rust-zh - Florob/RustyXML - 用 Rust 编写的 XML 解析器[<img src="https://api.travis-ci.org/Florob/RustyXML.svg?branch=master">](https://travis-ci.org/Florob/RustyXML) (库 / 编码(Encoding))
- awesome-rust - Florob/RustyXML - an XML parser (Libraries / Encoding)
- awesome-rust - Florob/RustyXML - ci.org/Florob/RustyXML.svg?branch=master">](https://travis-ci.org/Florob/RustyXML) (库 Libraries / 加密 Encoding)
- fucking-awesome-rust - Florob/RustyXML - an XML parser (Libraries / Encoding)
- fucking-awesome-rust - Florob/RustyXML - an XML parser (Libraries / Encoding)
README
RustyXML
========[![Build Status](https://travis-ci.org/Florob/RustyXML.svg?branch=master)](https://travis-ci.org/Florob/RustyXML)
[Documentation](https://docs.babelmonkeys.de/RustyXML/xml)
RustyXML is a namespace aware XML parser written in Rust.
Right now it provides a basic SAX-like API, and an ElementBuilder based on that.The parser itself is derived from OFXMLParser as found in ObjFW
.The current limitations are:
* Incomplete error checking
* Unstable APIThe Minimal Supported Rust Version for this crate is Rust 1.40.0.
Examples
--------
Parse a string into an `Element` struct:
```rust
use xml::Element;let elem: Option = "".parse();
```Get events from parsing string data:
```rust
use xml::{Event, Parser};// Create a new Parser
let mut p = Parser::new();// Feed data to be parsed
p.feed_str("");// Get events for the fed data
for event in p {
match event.unwrap() {
Event::ElementStart(tag) => println!("<{}>", tag.name),
Event::ElementEnd(tag) => println!("{}>", tag.name),
_ => ()
}
}
```Build `Element`s from `Parser` `Event`s:
```rust
use xml::{Parser, ElementBuilder};let mut p = xml::Parser::new();
let mut e = xml::ElementBuilder::new();p.feed_str("");
for elem in p.filter_map(|x| e.handle_event(x)) {
match elem {
Ok(e) => println!("{}", e),
Err(e) => println!("{}", e),
}
}
```Build `Element`s by hand:
```rust
let mut reply = xml::Element::new("iq".into(), Some("jabber:client".into()),
vec![("type".into(), None, "error".into()),
("id".into(), None, "42".into())]);
reply.tag(xml::Element::new("error".into(), Some("jabber:client".into()),
vec![("type".into(), None, "cancel".into())]))
.tag_stay(xml::Element::new("forbidden".into(),
Some("urn:ietf:params:xml:ns:xmpp-stanzas".into()),
vec![]))
.tag(xml::Element::new("text".into(),
Some("urn:ietf:params:xml:ns:xmpp-stanzas".into()),
vec![]))
.text("Permission denied".into());
```
Result (some whitespace added for readability):
```xml
Permission denied
```
Attribute Order
---------------By default the order of attributes is not tracked. Therefore during serialization and iteration
their order will be random. This can be changed by enabling the `ordered_attrs` feature.
With this feature enabled the order attributes were encountered while parsing,
or added to an `Element` will be preserved.License
-------Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)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.