shepmaster / sxd-document

An XML library in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Give line number and column number of error instead of single location value on parse error

Bellarmine-Head opened this issue · comments

This:-

fn main() {
    let xml = r#"<?xml version="1.0"?>
<bookshop>
  <books>
    <book>
      <title>The Illuminatus Trilogy</title>
    </book>
  </books>
</bookshop1>"#;

    let result = parser::parse(xml);

    match result {
        Ok(_) => println!("parsed ok"),
        Err((loc, errors)) => println!("parse failed; location = {}, errors = {:?}",
            loc, errors),
    }
}

will print:-

parse failed; location = 124, errors = [MismatchedElementEndName]

It would be nicer to give the line number and column number of the error, as all other XML parsers I've played with do.

Yep. Even better would be to copy what my other parser does and calculate the line / column and show a snippet.