media-io / yaserde

Yet Another Serializer/Deserializer
MIT License
175 stars 57 forks source link

Avoid XML Declaration in serialize. #91

Closed Armiixteryx closed 4 years ago

Armiixteryx commented 4 years ago

Hello. First I want to thank you for the work in this library, specially since XML support in Rust is not quite mature actually.

This issue is to see if it is possible to indicate yaserde to avoid serialize of XML declaration. Currently I am using some like this to remove it:

let s = yaserde::ser::to_string(&model).unwrap();
let s = s.replacen("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "", 1);

I think it would be better if yaserde may handle this case so creating a new String with replacen is no longer required.

Thanks for you attention.

MarcAntoine-Arnaud commented 4 years ago

Hello @Armiixteryx, It's already possible to skip the xml header.

You need to use to_string_with_config method, and the Config object contains the write_document_declaration field. If you set to false it will skip the xml header.

I close this issue, re-open if needed. Marc-Antoine