#XML #parser

RustyXML

A SAX-like streaming XML parser, and a DOM-like interface based on that

2 releases

0.1.1 Apr 3, 2015
0.1.0 Apr 1, 2015

#44 in Parser implementations

Download history 101/week @ 2018-08-13 180/week @ 2018-08-20 144/week @ 2018-08-27 116/week @ 2018-09-03 136/week @ 2018-09-10 149/week @ 2018-09-17 60/week @ 2018-09-24 105/week @ 2018-10-01 182/week @ 2018-10-08 197/week @ 2018-10-15 162/week @ 2018-10-22 76/week @ 2018-10-29 89/week @ 2018-11-05

145 downloads per month
Used in 20 crates (9 directly)

MIT license

53KB
1K SLoC

RustyXML

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 https://webkeks.org/objfw/.

The current limitations are:

  • Incomplete error checking
  • Unstable API

This project tracks Rust's master branch.

Examples

Parse a string into an Element struct:

use xml::Element;

let elem: Option<Element> = "<a href='//example.com'/>".parse();

Get events from parsing string data:

use xml::{Event, Parser};

// Create a new Parser
let mut p = Parser::new();

// Feed data to be parsed
p.feed_str("<a href");
p.feed_str("='//example.com'/>");

// 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),
        _ => ()
    }
}

This should print:

<a>
</a>

Build Elements from Parser Events:

use xml::{Parser, ElementBuilder};

let mut p = xml::Parser::new();
let mut e = xml::ElementBuilder::new();

p.feed_str("<a href='//example.com'/>");
for elem in p.filter_map(|x| e.handle_event(x)) {
    match elem {
        Ok(e) => println!("{}", e),
        Err(e) => println!("{}", e),
    }
}

License

This project is MIT licensed. Please see the COPYING file for more information.

Build Status

No runtime deps