The generated code with xsd-parser 1.5.2 fails to accept a derived type where the base type is expected. For example, the following schema uses xs:extension to create a derived type ConcreteDocument from AbstractDocument:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:complexType name="AbstractDocument" abstract="true" />
<xs:complexType name="ConcreteDocument">
<xs:complexContent>
<xs:extension base="AbstractDocument">
<xs:sequence maxOccurs="unbounded">
<xs:element name="info" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="document" type="AbstractDocument"/>
</xs:schema>
and the following xml uses xsi:type to specify the type of the instance as ConcreteDocument
<?xml version="1.0" encoding="utf-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ConcreteDocument">
<info>some info</info>
</document>
The code generated with
Config::default()
.with_schema(Schema::File("my-schema.xsd".into()))
.with_interpreter_flags(InterpreterFlags::all())
.with_optimizer_flags(OptimizerFlags::all())
.with_generator_flags(GeneratorFlags::all())
.with_quick_xml();
defines Document as an alias to AbstractDocument, which is an empty struct. Thus, Document::deserialize fails when encountering the info element:
Error { kind: UnexpectedEvent(Start(BytesStart { buf: Owned("info"), name_len: 4 })), position: Some(139), elements: Some(["document", "info"]) }
I expected the generated code to define AbstractDocument as an enum with variants for each derived type, similarly to how substitution groups are handled for xsd-parser/tests/optimizer/abstract.xsd in xsd-parser/tests/optimizer/expected1/convert_dynamic_to_choice.rs or to use Any like in xsd-parser/tests/optimizer/expected0/convert_dynamic_to_choice.rs.
Is there a way to generate code able to accept derived types in place of the base type or is this at the moment unsupported?
The generated code with xsd-parser 1.5.2 fails to accept a derived type where the base type is expected. For example, the following schema uses
xs:extensionto create a derived typeConcreteDocumentfromAbstractDocument:and the following xml uses
xsi:typeto specify the type of the instance asConcreteDocumentThe code generated with
defines
Documentas an alias toAbstractDocument, which is an empty struct. Thus,Document::deserializefails when encountering theinfoelement:I expected the generated code to define
AbstractDocumentas an enum with variants for each derived type, similarly to how substitution groups are handled for xsd-parser/tests/optimizer/abstract.xsd in xsd-parser/tests/optimizer/expected1/convert_dynamic_to_choice.rs or to use Any like in xsd-parser/tests/optimizer/expected0/convert_dynamic_to_choice.rs.Is there a way to generate code able to accept derived types in place of the base type or is this at the moment unsupported?