Module ser

Module ser 

Source
Expand description

Serde serializer for XML.

This module provides a full-featured Serde serializer that converts Rust data structures into XML documents.

§Attribute Serialization

Fields can be serialized as XML attributes by using the @ prefix:

use serde::Serialize;
use serde_xml::to_string;

#[derive(Serialize)]
struct Element {
    #[serde(rename = "@id")]
    id: String,
    #[serde(rename = "@class")]
    class: String,
    content: String,
}

let elem = Element {
    id: "main".to_string(),
    class: "container".to_string(),
    content: "Hello".to_string(),
};

let xml = to_string(&elem).unwrap();
// Output: <Element id="main" class="container"><content>Hello</content></Element>

Structs§

MapSerializer
Map serializer.
SeqSerializer
Sequence serializer.
Serializer
The XML serializer.
StructSerializer
Struct serializer with attribute support.

Functions§

to_string
Serializes a value to an XML string.
to_string_with_root
Serializes a value to an XML string with a root element name.
to_vec
Serializes a value to XML bytes.
to_writer
Serializes a value to a writer.