mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Fix TagList not writing the <prop> wrapper
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
use derive_more::derive::From;
|
use derive_more::derive::From;
|
||||||
use quick_xml::name::Namespace;
|
use quick_xml::{
|
||||||
|
events::{BytesEnd, BytesStart, Event},
|
||||||
|
name::Namespace,
|
||||||
|
};
|
||||||
use rustical_xml::{NamespaceOwned, XmlSerialize};
|
use rustical_xml::{NamespaceOwned, XmlSerialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -9,11 +12,37 @@ pub struct TagList(Vec<(Option<NamespaceOwned>, String)>);
|
|||||||
impl XmlSerialize for TagList {
|
impl XmlSerialize for TagList {
|
||||||
fn serialize<W: std::io::Write>(
|
fn serialize<W: std::io::Write>(
|
||||||
&self,
|
&self,
|
||||||
_ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
_tag: Option<&[u8]>,
|
tag: Option<&[u8]>,
|
||||||
_namespaces: &HashMap<Namespace, &[u8]>,
|
namespaces: &HashMap<Namespace, &[u8]>,
|
||||||
writer: &mut quick_xml::Writer<W>,
|
writer: &mut quick_xml::Writer<W>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
|
let prefix = ns
|
||||||
|
.map(|ns| namespaces.get(&ns))
|
||||||
|
.unwrap_or(None)
|
||||||
|
.map(|prefix| {
|
||||||
|
if !prefix.is_empty() {
|
||||||
|
[*prefix, b":"].concat()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let has_prefix = prefix.is_some();
|
||||||
|
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
|
||||||
|
let qname = tagname
|
||||||
|
.as_ref()
|
||||||
|
.map(|tagname| ::quick_xml::name::QName(tagname));
|
||||||
|
|
||||||
|
if let Some(qname) = &qname {
|
||||||
|
let mut bytes_start = BytesStart::from(qname.to_owned());
|
||||||
|
if !has_prefix {
|
||||||
|
if let Some(ns) = &ns {
|
||||||
|
bytes_start.push_attribute((b"xmlns".as_ref(), ns.as_ref()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.write_event(Event::Start(bytes_start))?;
|
||||||
|
}
|
||||||
|
|
||||||
for (ns, tag) in &self.0 {
|
for (ns, tag) in &self.0 {
|
||||||
let mut el = writer.create_element(tag);
|
let mut el = writer.create_element(tag);
|
||||||
if let Some(ns) = ns {
|
if let Some(ns) = ns {
|
||||||
@@ -21,6 +50,10 @@ impl XmlSerialize for TagList {
|
|||||||
}
|
}
|
||||||
el.write_empty()?;
|
el.write_empty()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(qname) = &qname {
|
||||||
|
writer.write_event(Event::End(BytesEnd::from(qname.to_owned())))?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user