Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to serialize and/or deserialize reserved xml attributes. #841

Open
jespersm opened this issue Jan 18, 2025 · 0 comments
Open

Comments

@jespersm
Copy link

Roundtripping a xml:lang attribute on an element is not possible.

Example:

#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct ElementWithXmlLang {
    #[serde(rename = "$text")]
    body: &'static str,
    #[serde(rename = "@xml:lang")]
    lang: &'static str,
}

// ...

serialize_as!(xml_lang_attribute: ElementWithXmlLang { body: "Ikke for sarte sjæle", lang: "da" }
                => "<root xml:lang=\"da\">Ikke for sarte sjæle</root>");                    

This serializes correctly, but fail to deserialize (deserialization roundtrip: Custom("missing field '@xml:lang'")), since the element has its 'xml' prefix stripped by the key handling inside key.rs (QNameDeserializer::from_attr), likely introduced when adressing #537.

Since the namespace handling is incomplete anyways (see my suggestions in #218), it would make sense to allow the 'xml' namespace to pass through so the example above could roundtrip.

Using #[serde(rename = "@lang")] works for deserializing, but is not desirable, since it allows unqualified names to go through, too.

jespersm added a commit to jespersm/quick-xml that referenced this issue Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant