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

duplicate field @type when both default and xsi namespace attribute are present #757

Closed
KarstenB opened this issue Jun 16, 2024 · 1 comment
Labels
duplicate help wanted namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML

Comments

@KarstenB
Copy link

The following code fails with called Result::unwrap()on anErrvalue: Custom("duplicate field@type"):

use quick_xml::de::from_str;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct MyType {
    pub sub: Sub,
}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct Sub {
    #[serde(rename = "@type")]
    // also doesn't work, but for a different reason:
    // Custom("missing field `@xsi:type`")
    //#[serde(rename="@xsi:type")]
    pub my_type: String,
}

fn main() {
    let xml=r#"
    <?xml version="1.0"?>
    <bla xmlns="http://myns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <sub type="a" xsi:type="b"/>
    </bla>"#;
    let object: MyType = from_str(&xml).unwrap();
}

I am not quite sure if this is a duplicate of #347, but wanted to contribute another piece of test code. Right now I do a stupid string replacement of xsi:type with xsi_type and quick-xml is still 10 times faster than some of there other crates I tried!

@Mingun Mingun added help wanted serde Issues related to mapping from Rust types to XML namespaces Issues related to namespaces support labels Jun 16, 2024
@Mingun
Copy link
Collaborator

Mingun commented Jun 16, 2024

Yes, namespace prefixes does not considered as part of field name because there can be different prefixes for the one namespace even in the same document. This problem is just one consequence of #218, so I close it as duplicate.

@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate help wanted namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants