SerializeAttribute

Derive Macro SerializeAttribute 

Source
#[derive(SerializeAttribute)]
{
    // Attributes available to this derive:
    #[xattribute]
}
Expand description

Derives the SerializeAttribute trait for a type.

This macro works to serialize to XML-attributes. To serialize to elements, use the Serialize derive macro instead.

NOTE: It is perfectly possible to derive both Serialize and SerializeAttribute for the same type, allowing the parent to decide which serialization method to use. Since deserialization can work from multiple sources, simply deriving Deserialize is sufficient to deserialize from either elements or attributes (depending on what is enabled through the derive macro).

To configure the serialization, use the #[xattribute(...)] attribute on the root of the type. This attribute is required.

§Configuration

§Serialize as an attribute - #[xattribute(...)] on the root of a type

§Options
Name Type Description
name String Element name.
namespace String Must be a valid namespace string. Exclusive with `namespace_expr`.
namespace_expr Expr Element namespace expression. This should be a value of type `xmlity::XmlNamespace`. Exclusive with `namespace`.
preferred_prefix String Must be a valid XML prefix.
enforce_prefix bool Enforce the use of the preferred prefix. If this is set to `true`, the preferred prefix will be used even if it there is already a prefix bound to the namespace.