TagList: Correctly write namespace

This commit is contained in:
Lennart
2025-06-04 20:12:47 +02:00
parent 1a827a164f
commit 22ed278dbb

View File

@@ -1,8 +1,5 @@
use derive_more::derive::From;
use quick_xml::{
events::{BytesStart, Event},
name::Namespace,
};
use quick_xml::name::Namespace;
use rustical_xml::{NamespaceOwned, XmlSerialize};
use std::collections::HashMap;
@@ -12,13 +9,17 @@ pub struct TagList(Vec<(Option<NamespaceOwned>, String)>);
impl XmlSerialize for TagList {
fn serialize<W: std::io::Write>(
&self,
ns: Option<Namespace>,
tag: Option<&[u8]>,
namespaces: &HashMap<Namespace, &[u8]>,
_ns: Option<Namespace>,
_tag: Option<&[u8]>,
_namespaces: &HashMap<Namespace, &[u8]>,
writer: &mut quick_xml::Writer<W>,
) -> std::io::Result<()> {
for (_ns, tag) in &self.0 {
writer.write_event(Event::Empty(BytesStart::new(tag)))?;
for (ns, tag) in &self.0 {
let mut el = writer.create_element(tag);
if let Some(ns) = ns {
el = el.with_attribute(("xmlns", String::from_utf8_lossy(&ns.0)));
}
el.write_empty()?;
}
Ok(())
}