Git Product home page Git Product logo

rust-xml-schema's Introduction

rust-xml-schema

XML Parser generator based on XML schemas.

Project status: pre-alpha

Features

  • Self-generating, meaning that all features used by XMLSchema.xsd (XML Schema's definition using XML Schema itself) are supported. This includes:
    • namespaces
    • group/choice/sequence/element
    • attributes
  • Most datatypes (some natively implemented, some generated via derived.nxsd)
  • Anonymous elements are given a name using a best-effort heuristic -- they are manually overridable

To do

  • simpleContent
  • some facets
  • anything related to XPath
  • assertions
  • time data types
  • notation
  • many other stuff, grep for TODO, unimplemented, unwrap, or expect in the code.
  • add tests
  • check conformance to the XSD specification

Regenerating the schema parser

wget https://www.w3.org/2009/XMLSchema/XMLSchema.xsd -O xml-schema/XMLSchema.xsd
wget https://www.w3.org/2009/XMLSchema/derived.nxsd -O xml-schema/derived.nxsd
cargo run --package xml-schema --bin gen xml-schema/derived.nxsd xml-schema/XMLSchema.xsd > foo.rs
cp foo.rs xml-schema/src/parser.rs
cargo test

rust-xml-schema's People

Contributors

progval avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rust-xml-schema's Issues

Permissive License

Would you consider using a permissive license like MIT/Apache?

Thanks

Failed to parse "mixed" attribute in complexType

I run in the following error when adding mixed="false" in the test_parser.rs.

const PERSON_XSD: &'static str = r#"
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="foo">
   <xs:element name="person">
     <xs:complexType abstract="false" mixed="false">
       <xs:sequence>
         <xs:element name="name" type="xs:string" />
         <xs:element name="firstname" type="xs:string" />
         <xs:element name="birthdate" type="xs:date" />
       </xs:sequence>
     </xs:complexType>
   </xs:element>
 </xs:schema>"#;
thread 'test_parser::generated_parses_person_xsd' panicked at 'Could not parse mixed="false", name=StrSpan("complexType" 122..133 -  
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="foo">
    <xs:element name="person">
      <xs:complexType mixed="false">
        <xs:sequence>
          <xs:element name="name" type="xs:string" />
          <xs:element name="firstname" type="xs:string" />
          <xs:element name="birthdate" type="xs:date" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:schema>)', xml-schema/src/parser.rs:2606:5

Failure if the target namespace is unqualified

e.g. MPD.xsd,

$ cargo run --package xml-schema --bin gen DASH-MPD.xsd > dash-mpd.rs                                                                                      
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s                                                                                                                                                      
     Running `target/debug/gen DASH-MPD.xsd`                                                                                                                                                                       
thread 'main' panicked at 'Some("urn:mpeg:dash:schema:mpd:2011")', src/libcore/option.rs:1034:5

I think this is because of the namespace definition in the schema:

<xs:schema
  targetNamespace="urn:mpeg:dash:schema:mpd:2011"
  attributeFormDefault="unqualified"
  elementFormDefault="qualified"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns="urn:mpeg:dash:schema:mpd:2011">

...the targetNamespace matches the unqualified namespace definition xmlns="urn:mpeg:dash:schema:mpd:2011".

(As a workaround, I can alter the schema so that the namespace definition is qualified, e.g. xmlns:mpd="urn:mpeg:dash:schema:mpd:2011")

Fails to generate MusicXML schema

MusicXML is a W3C standard for music notation.

I tried to play with rust-xml-schema and the MusicXML schema, and here is what happened:

$ wget https://raw.githubusercontent.com/w3c/musicxml/gh-pages/schema/musicxml.xsd -O xml-schema/musicxml.xsd
$ env RUST_BACKTRACE=full cargo run --package xml-schema --bin gen xml-schema/musicxml.xsd
thread 'main' panicked at 'Expected one of ["#all"], got "extension substitution"', xml-schema/src/primitives.rs:131:9
stack backtrace:
   0:     0x556d16e20524 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7b11b2a23cd910b3
   1:     0x556d16e363dc - core::fmt::write::hca7efce6c0791439
   2:     0x556d16e1ec37 - std::io::Write::write_fmt::he56b7f6fb86cf3b5
   3:     0x556d16e224de - std::panicking::default_hook::{{closure}}::hf51e7f0a7424f5cd
   4:     0x556d16e221d1 - std::panicking::default_hook::he8ba9c8182908cf7
   5:     0x556d16e22b0b - std::panicking::rust_panic_with_hook::hf9a08396e191b616
   6:     0x556d16e226be - rust_begin_unwind
   7:     0x556d16e22600 - std::panicking::begin_panic_fmt::hfd104289df6728bf
   8:     0x556d16d19c74 - <xml_schema::primitives::Token as xml_schema::support::ParseXmlStr>::parse_self_xml_str::h6908c3ad8b9d1f13
                               at xml-schema/src/primitives.rs:131
   9:     0x556d16d18140 - xml_schema::support::ParseXmlStr::parse_xml_str::hfdc9e574e37ca3fe
                               at xml-schema/src/support.rs:153
  10:     0x556d16d2ff4a - <xml_schema::parser::restrictions::All as xml_schema::support::ParseXmlStr>::parse_self_xml_str::h674cfbdd4c9cc9f7
                               at xml-schema/src/macros.rs:504
  11:     0x556d16d20b70 - xml_schema::support::ParseXmlStr::parse_xml_str::hd8070b50b6a4b405
                               at xml-schema/src/support.rs:153
  12:     0x556d16cce4d7 - <xml_schema::parser::unions::UnionTokenDerivationControlList as xml_schema::support::ParseXmlStr>::parse_self_xml_str::h3e6739fcab311459
                               at xml-schema/src/macros.rs:443
  13:     0x556d16ccd180 - xml_schema::support::ParseXmlStr::parse_xml_str::h80f7a12a3c644a00
                               at xml-schema/src/support.rs:153
  14:     0x556d16c1254e - <xml_schema::parser::xs::Element as xml_schema::support::ParseXml>::parse_self_xml::hff05a00496329bca
                               at xml-schema/src/macros.rs:276
  15:     0x556d16be39e0 - xml_schema::support::ParseXml::parse_xml::ha293b3e56aec22e8
                               at xml-schema/src/support.rs:136
  16:     0x556d16c7dfaf - <xml_schema::parser::xs::SchemaTop as xml_schema::support::ParseXml>::parse_self_xml::hc1daa1ae62f9dd63
                               at xml-schema/src/macros.rs:42
  17:     0x556d16be3de9 - xml_schema::support::ParseXml::parse_xml::hca4f4a3d53f262fe
                               at xml-schema/src/support.rs:136
  18:     0x556d16bc89f1 - <xml_schema::parser::sequences::SequenceSchemaTopAnnotation as xml_schema::support::ParseXml>::parse_self_xml::hb2d5f97c3eb45e30
                               at xml-schema/src/macros.rs:202
  19:     0x556d16bc7e5d - xml_schema::support::ParseXml::parse_xml::h2aef1b4d10491659
                               at xml-schema/src/support.rs:136
  20:     0x556d16c60e19 - <xml_schema::parser::xs::Schema as xml_schema::support::ParseXml>::parse_self_xml::h43b3b3e5a13031e7
                               at xml-schema/src/macros.rs:310
  21:     0x556d16be3400 - xml_schema::support::ParseXml::parse_xml::h565e80bf15f527ee
                               at xml-schema/src/support.rs:136
  22:     0x556d16b4db2e - xml_schema::parse_xsd_with_visitor::h517b71e70c030c7b
                               at xml-schema/src/lib.rs:39
  23:     0x556d16b1810f - gen::main::hc0991bd4eaf1bba4
                               at xml-schema/src/bin/gen.rs:44
  24:     0x556d16b14ce0 - std::rt::lang_start::{{closure}}::h0cb263f2fed267a6
                               at /build/rust/src/rustc-1.41.0-src/src/libstd/rt.rs:67
  25:     0x556d16e225a3 - std::panicking::try::do_call::hd0ef6b95899a3d3b
  26:     0x556d16e2438a - __rust_maybe_catch_panic
  27:     0x556d16e22fa0 - std::rt::lang_start_internal::hd59341531b4fe1e8
  28:     0x556d16b14cb9 - std::rt::lang_start::hbeacabebb6a1ef50
                               at /build/rust/src/rustc-1.41.0-src/src/libstd/rt.rs:67
  29:     0x556d16b18a0a - main
  30:     0x7fee0e2bf153 - __libc_start_main
  31:     0x556d16b0f0be - _start
  32:                0x0 - <unknown>

I opened this ticket for the record :) as rust-xml-schema is still in a very early stage.

Unable to parse the IEC 61131-10 Spec

I recently tried to use this against the IEC 61131 XSD spec (it's the file format used by most PLCs) and it complained about expecting the end of xsd:schema but finding the start of a xsd:complexType.

I'm guessing it's not able to handle multiple top-level items inside xsd:schema?

$ cargo run --package xml-schema --bin gen .\iec61131-10.xsd > schema.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target\debug\gen.exe .\iec61131-10.xsd`
thread 'main' panicked at 'Expected closing tag for xsd:schema, got Some(ElementStart(StrSpan("xsd" 12282..12285), StrSpan("complexType" 12286..12297)))', xml-schema\src\parser.rs:854:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: process didn't exit successfully: `target\debug\gen.exe .\iec61131-10.xsd` (exit code: 101)

Fails to generate JUnit schema

Schema source: link

Output:

$ ./target/release/gen JUnit.xsd
// Input: "JUnit.xsd"
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:345:21
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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.