Name Description Size
key.rs 16938
map.rs Serde `Deserializer` module 45001
mod.rs Serde `Deserializer` module. Due to the complexity of the XML standard and the fact that Serde was developed with JSON in mind, not all Serde concepts apply smoothly to XML. This leads to that fact that some XML concepts are inexpressible in terms of Serde derives and may require manual deserialization. The most notable restriction is the ability to distinguish between _elements_ and _attributes_, as no other format used by serde has such a conception. Due to that the mapping is performed in a best effort manner. Table of Contents ================= - [Mapping XML to Rust types](#mapping-xml-to-rust-types) - [Basics](#basics) - [Optional attributes and elements](#optional-attributes-and-elements) - [Choices (`xs:choice` XML Schema type)](#choices-xschoice-xml-schema-type) - [Sequences (`xs:all` and `xs:sequence` XML Schema types)](#sequences-xsall-and-xssequence-xml-schema-types) - [Composition Rules](#composition-rules) - [Enum Representations](#enum-representations) - [Normal enum variant](#normal-enum-variant) - [`$text` enum variant](#text-enum-variant) - [Difference between `$text` and `$value` special names](#difference-between-text-and-value-special-names) - [`$text`](#text) - [`$value`](#value) - [Primitives and sequences of primitives](#primitives-and-sequences-of-primitives) - [Structs and sequences of structs](#structs-and-sequences-of-structs) - [Enums and sequences of enums](#enums-and-sequences-of-enums) - [Frequently Used Patterns](#frequently-used-patterns) - [`<element>` lists](#element-lists) - [Overlapped (Out-of-Order) Elements](#overlapped-out-of-order-elements) - [Internally Tagged Enums](#internally-tagged-enums) Mapping XML to Rust types ========================= Type names are never considered when deserializing, so you can name your types as you wish. Other general rules: - `struct` field name could be represented in XML only as an attribute name or an element name; - `enum` variant name could be represented in XML only as an attribute name or an element name; - the unit struct, unit type `()` and unit enum variant can be deserialized from any valid XML content: - attribute and element names; - attribute and element values; - text or CDATA content (including mixed text and CDATA content). <div style="background:rgba(120,145,255,0.45);padding:0.75em;"> NOTE: All tests are marked with an `ignore` option, even though they do compile. This is because rustdoc marks such blocks with an information icon unlike `no_run` blocks. </div> <table> <thead> <tr><th colspan="2"> ## Basics </th></tr> <tr><th>To parse all these XML's...</th><th>...use these Rust type(s)</th></tr> </thead> <tbody style="vertical-align:top;"> <tr> <td> Content of attributes and text / CDATA content of elements (including mixed text and CDATA content): ```xml <... ...="content" /> ``` ```xml <...>content</...> ``` ```xml <...><![CDATA[content]]></...> ``` ```xml <...>text<![CDATA[cdata]]>text</...> ``` Mixed text / CDATA content represents one logical string, `"textcdatatext"` in that case. </td> <td> You can use any type that can be deserialized from an `&str`, for example: - [`String`] and [`&str`] - [`Cow<str>`] - [`u32`], [`f32`] and other numeric types - `enum`s, like ``` # use pretty_assertions::assert_eq; # use serde::Deserialize; # #[derive(Debug, PartialEq)] #[derive(Deserialize)] enum Language { Rust, Cpp, #[serde(other)] Other, } # #[derive(Debug, PartialEq, Deserialize)] # struct X { #[serde(rename = "$text")] x: Language } # assert_eq!(X { x: Language::Rust }, quick_xml::de::from_str("<x>Rust</x>").unwrap()); # assert_eq!(X { x: Language::Cpp }, quick_xml::de::from_str("<x>C<![CDATA[p]]>p</x>").unwrap()); # assert_eq!(X { x: Language::Other }, quick_xml::de::from_str("<x><![CDATA[other]]></x>").unwrap()); ``` <div style="background:rgba(120,145,255,0.45);padding:0.75em;"> NOTE: deserialization to non-owned types (i.e. borrow from the input), such as `&str`, is possible only if you parse document in the UTF-8 encoding and content does not contain entity references such as `&amp;`, or character references such as `&#xD;`, as well as text content represented by one piece of [text] or [CDATA] element. </div> <!-- TODO: document an error type returned --> [text]: Event::Text [CDATA]: Event::CData 166880
resolver.rs Entity resolver module 3249
simple_type.rs Contains Serde `Deserializer` for XML [simple types] [as defined] in the XML Schema. [simple types]: https://www.w3schools.com/xml/el_simpletype.asp [as defined]: https://www.w3.org/TR/xmlschema11-1/#Simple_Type_Definition 51668
text.rs 6187
var.rs 4644