Merge branch 'valid-xml' into 'master'

Make the Debug trait output valid XML

See merge request !1
This commit is contained in:
lumi 2017-04-02 20:50:40 +00:00
commit 8f027cfee2

View file

@ -31,15 +31,17 @@ pub struct Element {
impl fmt::Debug for Element { impl fmt::Debug for Element {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if let Some(ref ns) = self.namespace {
write!(fmt, "<{{{}}}{}", ns, self.name)?;
}
else {
write!(fmt, "<{}", self.name)?; write!(fmt, "<{}", self.name)?;
if let Some(ref ns) = self.namespace {
write!(fmt, " xmlns=\"{}\"", ns)?;
} }
for attr in &self.attributes { for attr in &self.attributes {
write!(fmt, " {}", attr)?; write!(fmt, " {}", attr)?;
} }
if self.children.is_empty() {
write!(fmt, "/>")?;
}
else {
write!(fmt, ">")?; write!(fmt, ">")?;
for child in &self.children { for child in &self.children {
match *child { match *child {
@ -52,6 +54,7 @@ impl fmt::Debug for Element {
} }
} }
write!(fmt, "</{}>", self.name)?; write!(fmt, "</{}>", self.name)?;
}
Ok(()) Ok(())
} }
} }