10 releases (6 breaking)

Uses old Rust 2015

0.7.0 Aug 4, 2018
0.6.2 Oct 1, 2017
0.6.1 Jul 7, 2017
0.5.0 Jul 5, 2017
0.1.1 Oct 13, 2015

#33 in #parse-tree

Download history 212/week @ 2023-12-17 25/week @ 2023-12-24 62/week @ 2023-12-31 202/week @ 2024-01-07 259/week @ 2024-01-14 103/week @ 2024-01-21 80/week @ 2024-01-28 68/week @ 2024-02-04 70/week @ 2024-02-11 61/week @ 2024-02-18 105/week @ 2024-02-25 84/week @ 2024-03-03 76/week @ 2024-03-10 75/week @ 2024-03-17 54/week @ 2024-03-24 328/week @ 2024-03-31

540 downloads per month
Used in 8 crates (7 directly)

MIT license

19KB
414 lines

treexml: An XML Tree Library for Rust

treexml is a simple element-tree style library for XML data.

Usage

Like most rust packages, treexml uses cargo. To use treexml, add the following to your project's Cargo.toml

[dependencies]
treexml = "0.7"

The package exposes a crate named treexml.

extern crate treexml;

Reading XML Data

extern crate treexml;

use treexml::Document;

fn main() {

    let doc_raw = r#"
    <?xml version="1.1" encoding="UTF-8"?>
    <table>
        <fruit type="apple">worm</fruit>
        <vegetable />
    </table>
    "#;

    let doc = Document::parse(doc_raw.as_bytes()).unwrap();
    let root = doc.root.unwrap();

    let fruit = root.find_child(|tag| tag.name == "fruit").unwrap().clone();
    println!("{} [{:?}] = {}", fruit.name, fruit.attributes, fruit.contents.unwrap());

}

Writing XML Data

extern crate treexml;

use treexml::{Document, ElementBuilder as E};

fn main() {
    let mut something = E::new("something");
    root.attr("key", "value");
    root.text("some-text");

    let doc = Document::build(
        E::new("root").children(vec![
            E::new("list").children(vec![
                E::new("child").cdata("test data here"),
                E::new("child").attr("class", "foo").text("bar"),
                E::new("child").attr("class", 22).text(11),
                &mut E::new("child"),
                &mut something,
            ]),
        ])
    );

    println!("{}", doc);

}

Contributing

This project is licensed under the MIT license.

If you encounter any issues, please file them on the GitHub issue tracker at https://github.com/rahulg/treexml/issues.

Dependencies

~315KB