quick-xml
quick-xml copied to clipboard
Processing instructions with embedded XML are not parsed correctly
I have XML input that contains XML within processing instructions. See the test code below.
As far as I can tell, these are well-formed according to the spec at https://www.w3.org/TR/xml11/#sec-pi and such XMLs can be successfully parsed with xml-rs and rapidxml in C++.
I looked into it but I am not yet proficient with macros, and I couldn't figure out if one should use &[u8] instead of u8 for XmlSource::read_bytes_until or have another method like XmlSource::read_bytes_until_slice. I found that the memchr crate seems to have explicit support for two bytes and also for slices in general.
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_procinst_xml() {
let xml = r#"<?xml version="1.0" encoding="utf-8"?>
<?procinst-with-xml
<parameters>
<parameter id="version" value="0.1"/>
<parameter id="timeStamp" value="2024-01-16T10:44:00Z"/>
</parameters>
?>
<Document/>"#;
let mut reader = Reader::from_str(xml);
loop {
match reader.read_event() {
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
Ok(Event::Eof) => break,
_ => (),
}
}
}
}