xml-rs icon indicating copy to clipboard operation
xml-rs copied to clipboard

Multiple roots should not be allowed

Open yblein opened this issue 8 years ago • 2 comments

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.

yblein avatar Apr 11 '16 13:04 yblein

Thanks, this is bad indeed. I was sure that this case was handled.

netvl avatar Apr 11 '16 13:04 netvl

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.

lo48576 avatar Aug 30 '16 09:08 lo48576

This is fixed in v0.8.9, and there is a config option to allow it again.

kornelski avatar May 09 '23 15:05 kornelski