Giter VIP home page Giter VIP logo

Comments (8)

oli-obk avatar oli-obk commented on June 5, 2024

Not yet, but this is trivial to implement in the parser. Maybe we should bail out with an error if standalone is "no"

from serde-xml-rs.

kjeremy avatar kjeremy commented on June 5, 2024

I'm looking at this right now (I'm a total rust newbie) and I don't understand why it doesn't work.

The following in inner_next should handle it:

match r.map_err(ErrorKind::Syntax)? {
                XmlEvent::StartDocument { .. } |

from serde-xml-rs.

oli-obk avatar oli-obk commented on June 5, 2024

That seems too general. You'd skip over every kind of syntax error. I also am not sure if xml-rs even supports recovering from syntax errors. Have you checked whether xml-rs supports headers in some way?

from serde-xml-rs.

RReverser avatar RReverser commented on June 5, 2024

xml-rs definitely supports <?xml ...?> if that's what you mean by headers, it's in its own test suite: https://github.com/netvl/xml-rs/blob/master/tests/documents/sample_1.xml

from serde-xml-rs.

RReverser avatar RReverser commented on June 5, 2024

And it's returned as StartDocument, which we already ignore. @kjeremy please provide more details - full reproducible example and an error message you're getting would be helpful.

from serde-xml-rs.

kjeremy avatar kjeremy commented on June 5, 2024

Right it returns StartDocument which is why I'm surprised. The following test illustrates the problem and fails with a parsing error.

#[test]
fn ignore_header() {
    init_logger();

    let s = r#"
        <?xml version=”1.0” standalone=”yes”?>
        <item name="hello" source="world.rs" />
    "#;

    let item: Item = from_str(s).unwrap();

    assert_eq!(
        item,
        Item {
            name: "hello".to_string(),
            source: "world.rs".to_string(),
        }
    );
}

thread 'ignore_header' panicked at 'called Result::unwrap() on an Err value: Error(Syntax(Error { pos: 3:9, kind: Syntax("Unexpected token inside attribute value: <") }), State { next_error: None, backtrace: None })', src\libcore\result.rs:906:4

from serde-xml-rs.

RReverser avatar RReverser commented on June 5, 2024

@kjeremy If it's literally your XML, then the problem appears to be these weird quotes you have in the test - (U+201D) in <?xml ...?> vs normal quote " (U+0022) everywhere else. Perhaps copied incorrectly from somewhere?

from serde-xml-rs.

kjeremy avatar kjeremy commented on June 5, 2024

Ah ha! Good catch. Yes I had originally copied some XML from a word doc. Replacing the quotes fixed the issue. I will close this.

from serde-xml-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.