xml-rs
xml-rs copied to clipboard
Multiple roots should not be allowed
xml-rs is accepting documents with multiple root nodes while the XML specifications says that a document must have a unique root.
For instance, the following program
extern crate xml;
use xml::reader::{EventReader, XmlEvent};
fn main() {
for e in EventReader::new(&b"<a/><a/>"[..]) {
match e {
Ok(XmlEvent::StartElement { name, .. }) => {
println!("start: {}", name);
}
Err(e) => {
println!("error: {}", e);
break;
}
_ => {}
}
}
}
will print
start: a
start: a
instead of an error.
The issue exists both in 0.3
and master
.
Thanks, this is bad indeed. I was sure that this case was handled.
EventReader
can be used to read partial XML (such as DocumentFragment?).
I think it is better that handling of multiple root nodes can be controllable by ParserConfig
, rather than treat it as error always.
This is fixed in v0.8.9, and there is a config option to allow it again.