mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Merge branch 'valid-xml' into 'master'
Make the Debug trait output valid XML See merge request !1
This commit is contained in:
commit
8f027cfee2
1 changed files with 18 additions and 15 deletions
|
@ -31,27 +31,30 @@ pub struct Element {
|
|||
|
||||
impl fmt::Debug for Element {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "<{}", self.name)?;
|
||||
if let Some(ref ns) = self.namespace {
|
||||
write!(fmt, "<{{{}}}{}", ns, self.name)?;
|
||||
}
|
||||
else {
|
||||
write!(fmt, "<{}", self.name)?;
|
||||
write!(fmt, " xmlns=\"{}\"", ns)?;
|
||||
}
|
||||
for attr in &self.attributes {
|
||||
write!(fmt, " {}", attr)?;
|
||||
}
|
||||
write!(fmt, ">")?;
|
||||
for child in &self.children {
|
||||
match *child {
|
||||
Node::Element(ref e) => {
|
||||
write!(fmt, "{:?}", e)?;
|
||||
},
|
||||
Node::Text(ref s) => {
|
||||
write!(fmt, "{}", s)?;
|
||||
},
|
||||
}
|
||||
if self.children.is_empty() {
|
||||
write!(fmt, "/>")?;
|
||||
}
|
||||
else {
|
||||
write!(fmt, ">")?;
|
||||
for child in &self.children {
|
||||
match *child {
|
||||
Node::Element(ref e) => {
|
||||
write!(fmt, "{:?}", e)?;
|
||||
},
|
||||
Node::Text(ref s) => {
|
||||
write!(fmt, "{}", s)?;
|
||||
},
|
||||
}
|
||||
}
|
||||
write!(fmt, "</{}>", self.name)?;
|
||||
}
|
||||
write!(fmt, "</{}>", self.name)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue