1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
use crate::{QueryResult, QueryValue}; use crate::value::display_value; use super::utils::{escape_xml_tag, escape_xml_text}; pub fn render_xml(result: &QueryResult) -> String { let mut output = String::from("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<data>\n"); for row in &result.rows { output.push_str(" <row>\n"); for (column_index, column) in result.columns.iter().enumerate() { let value = row.get(column_index).unwrap_or(&QueryValue::Null); let xml_column = escape_xml_tag(column); let xml_value = escape_xml_text(&display_value(value)); output.push_str(&format!( " <{}>{}</{}>\n", xml_column, xml_value, xml_column )); } output.push_str(" </row>\n"); } output.push_str("</data>"); output }