implement write end tag
This commit is contained in:
parent
caf8b7506e
commit
0175a2d365
|
@ -13,7 +13,7 @@ use crate::{
|
|||
pub struct Writer<W> {
|
||||
inner: W,
|
||||
depth: Vec<Name>,
|
||||
namespaces: Vec<HashSet<NamespaceDeclaration>>,
|
||||
namespace_declarations: Vec<HashSet<NamespaceDeclaration>>,
|
||||
}
|
||||
|
||||
impl<W: AsyncWrite + Unpin> Writer<W> {
|
||||
|
@ -26,28 +26,36 @@ impl<W: AsyncWrite + Unpin> Writer<W> {
|
|||
}
|
||||
|
||||
pub async fn write_end(&mut self) -> Result<(), Error> {
|
||||
todo!()
|
||||
// let e_tag;
|
||||
// if let Some(name) = self.depth.pop() {
|
||||
// if let Some(prefix) = name.namespace.prefix {
|
||||
// e_tag = xml::ETag {
|
||||
// name: xml::QName::PrefixedName(xml::PrefixedName {
|
||||
// prefix: xml::Prefix::parse_full(&prefix)?,
|
||||
// local_part: xml::LocalPart::parse_full(&name.name)?,
|
||||
// }),
|
||||
// };
|
||||
// e_tag.write(&mut self.inner).await?;
|
||||
// Ok(())
|
||||
// } else {
|
||||
// e_tag = xml::ETag {
|
||||
// name: xml::QName::UnprefixedName(xml::UnprefixedName::parse_full(&name.name)?),
|
||||
// };
|
||||
// e_tag.write(&mut self.inner).await?;
|
||||
// Ok(())
|
||||
// }
|
||||
// } else {
|
||||
// return Err(Error::NotInElement("".to_string()));
|
||||
// }
|
||||
let e_tag;
|
||||
if let Some(name) = &self.depth.pop() {
|
||||
let namespace_declarations_stack: Vec<_> =
|
||||
self.namespace_declarations.iter().flatten().collect();
|
||||
let namespace_declaration = namespace_declarations_stack
|
||||
.iter()
|
||||
.rfind(|namespace_declaration| namespace_declaration.namespace == name.namespace)
|
||||
// will always be in this vector
|
||||
.unwrap();
|
||||
let prefix = &namespace_declaration.prefix;
|
||||
if let Some(prefix) = &prefix {
|
||||
e_tag = xml::ETag {
|
||||
name: xml::QName::PrefixedName(xml::PrefixedName {
|
||||
prefix: xml::Prefix::parse_full(prefix)?,
|
||||
local_part: xml::LocalPart::parse_full(&name.local_name)?,
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
e_tag = xml::ETag {
|
||||
name: xml::QName::UnprefixedName(xml::UnprefixedName::parse_full(
|
||||
&name.local_name,
|
||||
)?),
|
||||
};
|
||||
}
|
||||
e_tag.write(&mut self.inner).await?;
|
||||
self.namespace_declarations.pop();
|
||||
Ok(())
|
||||
} else {
|
||||
return Err(Error::NotInElement("".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue