UNC-Libraries / jquery.xmleditor

jQuery based XML editor plugin.
153 stars 71 forks source link

xsd2json: Missing sub elements when using substitutionGroup #84

Closed vog closed 7 years ago

vog commented 7 years ago

The following Schema defines

<schema xmlns:foo="http://example.com/foo" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/foo" elementFormDefault="qualified">
  <complexType name="BaseType">
    <sequence/>
  </complexType>
  <complexType name="FooType">
    <complexContent>
      <restriction base="foo:BaseType">
        <sequence>
          <element name="Bar">
            <complexType>
              <simpleContent>
                <extension base="string">
                  <attribute name="bar" type="string"/>
                </extension>
              </simpleContent>
            </complexType>
          </element>
        </sequence>
      </restriction>
    </complexContent>
  </complexType>
  <element name="Base" type="foo:BaseType"/>
  <element name="Foo" type="foo:FooType" substitutionGroup="foo:Base"/>
</schema>

Current output (relevant part):

    {
      "values": [],
      "type": null,
      "ns": 3,
      "name": "Foo",
      "element": true,
      "attributes": [],
      "elements": []
    }

Expected output (relevant part):

    {
      "values": [],
      "type": null,
      "ns": 3,
      "name": "Foo",
      "element": true,
      "attributes": [],
      "elements": [
        {
          "values": [],
          "type": "string",
          "ns": 3,
          "name": "Bar",
          "element": true,
          "attributes": [
            {
              "values": [],
              "type": "string",
              "ns": 3,
              "name": "bar",
              "attribute": true
            }
          ],
          "elements": []
        }
      ]
    }

Workarounds:

vog commented 7 years ago

Provided full test case in #85.

vog commented 7 years ago

This issue is closely related to #68. The same section of the XML Schema standard is relevant here:

https://www.w3.org/TR/xmlschema11-1/#declare-element

An <element> with no referenced or included type definition will correspond to an element declaration which has the same type definition as the first substitution-group head named in the substitutionGroup [attribute], if present, otherwise xs:anyType.