I'm trying to parse custom XML file formats with PyXB. So, I first wrote the following XML schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="outertag" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="innertag0"
minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="innertag1"
minOccurs="0"
maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
I used the following pyxbgen command to generate the Python module's source, py_schema_module.py:
pyxbgen -m py_schema_module -u schema.xsd
I then wrote the following script for parsing an XML file I call example.xml:
#!/usr/bin/env python2.7
import py_schema_module
if __name__ == "__main__":
with open("example.xml", "r") as f:
py_schema_module.CreateFromDocument(f.read())
I use that script to determine the legality of example.xml's syntax. For instance, the following example.xml file has legal syntax per the schema:
<outertag>
<innertag0></innertag0>
<innertag1></innertag1>
</outertag>
So does this:
<outertag>
<innertag1></innertag1>
<innertag0></innertag0>
</outertag>
However, the following syntax is illegal:
<outertag>
<innertag1></innertag1>
<innertag0></innertag0>
<innertag1></innertag1>
</outertag>
So is this:
<outertag>
<innertag0></innertag0>
<innertag1></innertag1>
<innertag0></innertag0>
</outertag>
I am able to write innertag0 and then innertag1. I am also able to write innertag1 and then innertag0. I can also repeat the instances of innertag0 and innertag1 arbitrarily (examples not shown for the sake of brevity). However, what I cannot do is switch between innertag0 and innertag1.
Let's assume I want the format to support this functionality. How should I alter my XML schema file?