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 have tag on each item? #287

Closed
azzamsa opened this issue May 27, 2021 · 1 comment · Fixed by #490
Closed

How to have tag on each item? #287

azzamsa opened this issue May 27, 2021 · 1 comment · Fixed by #490
Assignees
Labels
enhancement serde Issues related to mapping from Rust types to XML

Comments

@azzamsa
Copy link

azzamsa commented May 27, 2021

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

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML labels May 21, 2022
@Mingun Mingun self-assigned this Sep 7, 2022
Mingun added a commit to Mingun/quick-xml that referenced this issue Oct 1, 2022
Fixes tafia#252 - ok
Fixes tafia#280 - ok
Fixes tafia#287 - ok
Fixes tafia#343 - ok
Fixes tafia#346 - not ok
Fixes tafia#361 - ok
Partially addresses tafia#368
Fixes tafia#429 - ok
Fixes tafia#430 - ok
Mingun added a commit to Mingun/quick-xml that referenced this issue Oct 1, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430
@Mingun
Copy link
Collaborator

Mingun commented Oct 2, 2022

When #490 will be merged, the original code will always produce elements instead of attributes. If you would want attributes you should rename field to prepend a @ character to it

Mingun added a commit to Mingun/quick-xml that referenced this issue Oct 24, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests
Mingun added a commit to Mingun/quick-xml that referenced this issue Oct 25, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests
Mingun added a commit to Mingun/quick-xml that referenced this issue Oct 26, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests

Co-authored-by: Daniel Alley <dalley@redhat.com>
JOSEPHGILBY pushed a commit to JOSEPHGILBY/quick-xml that referenced this issue Nov 5, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests

Co-authored-by: Daniel Alley <dalley@redhat.com>
JOSEPHGILBY pushed a commit to JOSEPHGILBY/quick-xml that referenced this issue Nov 5, 2022
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests

Co-authored-by: Daniel Alley <dalley@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants