XML to JSON rust library - xml_to_json_rs
Rust library to convert an XML string to serde_json::Value
This library is designed to be simple and create serde_json::Value.
It supports
- Strings
- Arrays
- Objects
Numbers and Booleans will just be parsed as String, as they also look the same in XML.
The inner text attributes will be wrapped by default into #text and attributes will
get an @, for example @href. By this, the result will be consistent and can
be transformed back to XML. This library is not using $text as this creates
issues with MongoDB.
To transform the JSON back to XML, you can use prepare_for_quick_xml and quick-xml:
let simple_xml = "<a><b>simple</b></a>";
let parser = default;
let json_value = parser.xml_to_json.unwrap;
let comp_value = parser.prepare_for_quick_xml;
assert_eq!;
Check the tests in src/libs.rs to see further usage examples.
Usage:
    let simple_xml = "<a><b>simple</b></a>";
    assert_eq!;
    let nested_with_xml_with_attributes =
        "<a><b href=\"#self\">simple</b><b><c class=\"my_class\"><d>D</d><d>1</d></c></b></a>";
    assert_eq!;