Crates.io | treexml |
lib.rs | treexml |
version | 0.7.0 |
source | src |
created_at | 2015-10-12 10:22:23.623309 |
updated_at | 2018-08-04 19:45:51.393237 |
description | An XML tree library for Rust |
homepage | |
repository | https://github.com/rahulg/treexml-rs |
max_upload_size | |
id | 3202 |
size | 36,057 |
treexml
: An XML Tree Library for Rusttreexml
is a simple element-tree style library for XML data.
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;
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());
}
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);
}
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.