fix: add xml utf8 and semver declaration

This commit is contained in:
Cain 2024-02-02 21:10:41 +00:00
parent 4675b24ff3
commit 48aa5115c0

View file

@ -279,7 +279,7 @@ fn output_result_json_pretty<T: serde::Serialize>(result: T) -> Result<()> {
#[cfg(feature = "xml")]
fn output_result_xml<T: serde::Serialize>(result: T) -> Result<()> {
use quick_xml::{
events::{BytesEnd, BytesStart, BytesText, Event},
events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event},
Writer,
};
use serde_json::Value;
@ -292,6 +292,9 @@ fn output_result_xml<T: serde::Serialize>(result: T) -> Result<()> {
// Initialize the XML writer with a new, empty vector to store the XML data.
let mut writer = Writer::new(Vec::new());
// Write the XML 1.1 declaration
writer.write_event(Event::Decl(BytesDecl::new("1.1", Some("utf-8"), None)))?;
// Define a recursive function `json_to_xml` to convert the JSON value into XML
// format. The function takes a mutable reference to the XML writer, an
// optional key as a string slice, and a reference to the JSON value to be