RazrFalcon / xmlparser

A low-level, pull-based, zero-allocation XML 1.0 parser.
Apache License 2.0
130 stars 16 forks source link

Allow processing instruction before doctype #13

Closed mohe2015 closed 4 years ago

mohe2015 commented 4 years ago

Hi, the following

fn main() {
    let contents = r#"<!DOCTYPE greeting SYSTEM "hello.dtd"> <?xml-stylesheet?>"#;

    for token in xmlparser::Tokenizer::from(contents) {
        println!("{:?}", token);
    }

    let contents = r#"<?xml-stylesheet?> <!DOCTYPE greeting SYSTEM "hello.dtd">"#;

    for token in xmlparser::Tokenizer::from(contents) {
        println!("{:?}", token);
    }
}

outputs

Ok(EmptyDtd { name: StrSpan("greeting" 10..18), external_id: Some(System(StrSpan("hello.dtd" 27..36))), span: StrSpan("<!DOCTYPE greeting SYSTEM \"hello.dtd\">" 0..38) })
Ok(ProcessingInstruction { target: StrSpan("xml-stylesheet" 41..55), content: None, span: StrSpan("<?xml-stylesheet?>" 39..57) })
Ok(ProcessingInstruction { target: StrSpan("xml-stylesheet" 2..16), content: None, span: StrSpan("<?xml-stylesheet?>" 0..18) })
Err(UnknownToken(TextPos { row: 1, col: 20 }))

but should probably be able to parse as I found this in the wild. This is probably related to https://github.com/RazrFalcon/xmlparser/commit/94638df5244b5ebfbe0ba76961399a80c4ddf4d1 and https://github.com/RazrFalcon/xmlparser/issues/11

A fix would be really appreciated.