Skip to content

How to have tag on each item? #287

Closed
@azzamsa

Description

@azzamsa

I have struct Person.

#[derive(serde::Serialize)]
pub struct Person {
    name: String,
    age: i32,
}

and I want to parse it to XML string:

<Person><name>Foo</name><age>20</age></Person>

But I can't find a way to do it in quick-xml. https://docs.rs/quick-xml/0.22.0/quick_xml/se/fn.to_string.html

#[derive(serde::Serialize)]
pub struct Person {
    name: String,
    age: i32,
}

fn main() {
    let person = Person {
        name: "Foo".to_string(),
        age: 20,
    };

    let data_xml = quick_xml::se::to_string(&person).unwrap(); // how to have open-closed tag ??
    println!("{}", data_xml);
}

My current workaround is to use serde_xml_rs.

let data_xml = serde_xml_rs::to_string(&person).unwrap();

Is there a way to do this? So that I don't need multiple XML dependencies.

Thanks for quick-xml

Metadata

Metadata

Assignees

Labels

enhancementserdeIssues related to mapping from Rust types to XML

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions