[][src]Crate simple_xml

XML parser and writer This crate can load xml from a file or string and parse it into memory XML can also be manipulated or created and the written to file

Loading xml from a file

fn load_message() -> Result<(), simple_xml::Error> {
    let root = simple_xml::from_file("examples/message.xml")?;
    // Since there can multiple nodes/tags with the same name, we need to index twice
    let heading = &root["heading"][0];
    println!("Heading: {}", heading.content);
    // Access attributes
    let lang = root.get_attribute("lang").expect("Missing lang attribute");
    println!("Language: {}", lang);
    Ok(())
}

Creating xml structures

let name = String::from("Tim Roberts");
let health = 50;

let mut player = simple_xml::new("player", String::new());
player.add_new_node("health", health.to_string());
player.add_new_node("name", name);
// Save to file
player.save_to_file("./player.xml");

For more example, see the tests

Re-exports

pub use error::Error;
pub use error::ParseError;

Modules

error

Structs

Node

Functions

from_file

Loads an xml structure from a file and returns appropriate errors

from_string

Loads an xml structure from a string and returns appropriate errors

new

Creates a new empty node Nodes and attributes can be added later Content is taken owned as to avoid large copy Tag is not taken owned as it is most often a string literal

new_filled

Creates a new node with given tag, attributes content, and child nodes