element: Fix element name comparison in from_reader

quick-xml's Events seem to always return prefixed names, and the
from_reader function, when comparing name of the pop-ed element, and
received event element, was using the unprefixed name to compare.
This commit is contained in:
Maxime “pep” Buquet 2017-12-30 16:48:07 +01:00
parent 4685becf84
commit 1c3a701d2e

View file

@ -191,6 +191,11 @@ impl Element {
&self.name
}
/// Returns a reference to the prefix of this element.
pub fn prefix(&self) -> Option<String> {
self.prefix.clone()
}
/// Returns a reference to the namespace of this element, if it has one, else `None`.
pub fn ns(&self) -> Option<String> {
self.namespaces.get(&self.prefix)
@ -318,7 +323,11 @@ impl Element {
}
let elem = stack.pop().unwrap();
if let Some(to) = stack.last_mut() {
if elem.name().as_bytes() != e.name() {
let name = match elem.prefix() {
Some(ref prefix) => format!("{}:", prefix.clone()),
None => String::from(""),
} + elem.name();
if name.as_bytes() != e.name() {
bail!(ErrorKind::InvalidElementClosed);
}
to.append_child(elem);