#xml #parse #xmltree

xmltree

Parse an XML file into a simple tree-like structure

10 releases (6 breaking)

0.8.0 Feb 7, 2018
0.6.1 Sep 26, 2017
0.4.0 Mar 26, 2017
0.3.2 Apr 23, 2016
0.2.1 Aug 19, 2015

#26 in Data structures

Download history 817/week @ 2018-10-11 951/week @ 2018-10-18 686/week @ 2018-10-25 1111/week @ 2018-11-01 1042/week @ 2018-11-08 999/week @ 2018-11-15 1019/week @ 2018-11-22 1074/week @ 2018-11-29 1075/week @ 2018-12-06 1164/week @ 2018-12-13 884/week @ 2018-12-20 520/week @ 2018-12-27 512/week @ 2019-01-03

4,901 downloads per month
Used in 37 crates (15 directly)

MIT license

12KB
219 lines

xmltree-rs

Documention

A small library for parsing an XML file into an in-memory tree structure.

Not recommended for large XML files, as it will load the entire file into memory.

https://crates.io/crates/xmltree

Usage

Add the following to your Cargo.toml file:

[dependencies]
xmltree = "0.7"

and this to yoru crate root:

extern crate xmltree;

Example

See the documentation for the latest version:

https://docs.rs/xmltree/


lib.rs:

A simple library for parsing an XML file into an in-memory tree structure

Not recommended for large XML files, as it will load the entire file into memory.

Example

use xmltree::Element;
use std::fs::File;

let data: &'static str = r##"
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<names>
    <name first="bob" last="jones" />
    <name first="elizabeth" last="smith" />
</names>
"##;

let mut names_element = Element::parse(data.as_bytes()).unwrap();

println!("{:#?}", names_element);
{
    // get first `name` element
    let name = names_element.get_mut_child("name").expect("Can't find name element");
    name.attributes.insert("suffix".to_owned(), "mr".to_owned());
}
names_element.write(File::create("result.xml").unwrap());


Dependencies

~206KB