xml-rs based deserializer for Serde (compatible with 1.0+)
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information.
src Some Refactoring Aug 23, 2017
tests Some Refactoring Aug 23, 2017
.gitignore First working version Feb 16, 2017
.travis.yml Allow failures on nightly Rust Mar 12, 2017
Cargo.toml Convert error handling into error_chain Aug 17, 2017
LICENSE Initial commit Feb 16, 2017
README.md Fix #59 Dec 5, 2017
rustfmt.toml Run rustfmt Aug 21, 2017



Build Status

xml-rs based deserializer for Serde (compatible with 0.9+)


Use serde_xml_rs::deserialize(...) on any type that implements std::io::Read as following:

#[macro_use] extern crate serde_derive;
extern crate serde_xml_rs;

use serde_xml_rs::deserialize;

#[derive(Debug, Deserialize)]
struct Item {
    pub name: String,
    pub source: String

#[derive(Debug, Deserialize)]
struct Project {
    pub name: String,

    #[serde(rename = "Item", default)]
    pub items: Vec<Item>

fn it_works() {
    let s = r##"
        <Project name="my_project">
            <Item name="hello" source="world.rs" />
    let project: Project = deserialize(s.as_bytes()).unwrap();
    println!("{:#?}", project);

Alternatively, you can use serde_xml_rs::Deserializer to create a deserializer from a preconfigured xml_rs::EventReader.

Parsing the "value" of a tag

If you have an input of the form <foo abc="xyz">bar</foo>, and you want to get at thebar, you can use the special name $value:

struct Foo {
  pub abc String,
  #[serde(rename = "$value")]
  pub body String,

Parsed representations

Deserializer tries to be as intuitive as possible.

However, there are some edge cases where you might get unexpected errors, so it's best to check out tests for expectations.