15 unstable releases (7 breaking)

0.8.0 May 3, 2025
0.6.0 Aug 31, 2022
0.5.1 Sep 21, 2021
0.4.1 Jan 10, 2021
0.1.2 Mar 20, 2017

#59 in Encoding

Download history 99342/week @ 2025-02-01 93811/week @ 2025-02-08 86000/week @ 2025-02-15 100538/week @ 2025-02-22 101363/week @ 2025-03-01 105757/week @ 2025-03-08 111129/week @ 2025-03-15 99833/week @ 2025-03-22 99319/week @ 2025-03-29 104681/week @ 2025-04-05 107965/week @ 2025-04-12 132838/week @ 2025-04-19 137109/week @ 2025-04-26 141499/week @ 2025-05-03 145374/week @ 2025-05-10 117980/week @ 2025-05-17

565,034 downloads per month
Used in 761 crates (310 directly)

MIT license

155KB
4.5K SLoC

serde-xml-rs

Rust

xml-rs based serializer and deserializer for Serde (compatible with 1.0)

Example usage

use serde::{Deserialize, Serialize};
use serde_xml_rs::{from_str, to_string};

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

fn main() {
    let src = r#"<?xml version="1.0" encoding="UTF-8"?><Item><name>Banana</name><source>Store</source></Item>"#;
    let should_be = Item {
        name: "Banana".to_string(),
        source: "Store".to_string(),
    };

    let item: Item = from_str(src).unwrap();
    assert_eq!(item, should_be);

    let reserialized_item = to_string(&item).unwrap();
    assert_eq!(src, reserialized_item);
}

Breaking changes in version 0.8.0

Notably:

  • The $value name has been changed to #content (could become configurable in the future).
  • Fields that are deserialized from attributes must now have a name that starts with a @. This aligns with what was introduced in the serializer.

See MIGRATION.md for more details, and tips on how to migrate.

Dependencies

~0.6–1.2MB
~26K SLoC