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.
- Struct
Serializer - 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.