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

How to capture additional (unknown) nodes? #789

Closed
firewave-remo opened this issue Jul 23, 2024 · 2 comments
Closed

How to capture additional (unknown) nodes? #789

firewave-remo opened this issue Jul 23, 2024 · 2 comments
Labels
question serde Issues related to mapping from Rust types to XML

Comments

@firewave-remo
Copy link

I do have an XML where i am only interested in certain nodes and attributes, but I do need the other nodes and attributes of the XML to serialize them again later. I don't know what these nodes are called and what attributes they have and if they have additional subnodes.

Example

#[derive(Debug, Deserialize, Serialize)]
struct A {
    #[serde(rename = "@B")]
    b: B,
    #[serde(flatten)]
    other: ???, // How to capture additional elements with their attributes?
}

#[derive(Debug, Deserialize, Serialize)]
struct B {
    #[serde(rename = "@battribute")]
    attribute: String,
    #[serde(flatten)]
    other: Map<String, String>, // any additional attributes
}

...

let xml = r#"
    <?xml version="1.0" encoding="utf-8"?>
    <A>
        <B battribute="..." />
        <C cattribite1="..." cattribute2="">
            <D dattribute1="..." </D>
        </C>
    </A>"#;

I was able to capture additional attribute with

#[serde(flatten)]
other: Map<String, String>, // any additional attributes

But i don't know how to achieve this with full nodes. So i am looking for a serde_json::Value equivalent to perform what is described in the serde docs https://serde.rs/attr-flatten.html#capture-additional-fields

Thx for help

@Mingun
Copy link
Collaborator

Mingun commented Jul 23, 2024

Looks like duplicate of #383

@Mingun Mingun added question serde Issues related to mapping from Rust types to XML labels Jul 23, 2024
@firewave-remo
Copy link
Author

Yeah looks like it. Sorry I went through dozens of Issues but was not able to find this one. Hope there will be a solution in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants