media-io / yaserde

Yet Another Serializer/Deserializer
MIT License
174 stars 58 forks source link

Can an XML element name be used as a struct's attribute? #184

Closed antis81 closed 1 month ago

antis81 commented 2 months ago

The source XML I am serializing looks like this:

<property name="abc">
  <string>Hello World!</string>
</property>

Now I like to use the "string" to differentiate property types (string, bool, int, …).

#[derive(PartialEq, Debug, YaDeserialize)]
#[yaserde(rename = "property")]
pub struct Property {
    #[yaserde(attribute)]
    pub name: String,
    #[yaserde()]
    pub value: Option<PropertyValue>,
}

#[derive(PartialEq, Debug, YaDeserialize)]
pub struct PropertyValue {
    #[yaserde(tag)]
    pub prop_type: String,
    #[yaserde()]
    pub prop_value: String,
}

Is it implemented already? I couldn't find any documentation about that.

antis81 commented 1 month ago

XML enum is exactly meant for this -> closing