Use choice to define elements with random number and occurence
File: Data.xml
<?xml version="1.0"?>
<binary-string xmlns="http://www.java2s.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.java2s.com Schema.xsd">
<one/>
<one>1</one>
<zero/>
<one>1</one>
<zero>0</zero>
</binary-string>
File: Schema.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.java2s.com"
xmlns="http://www.java2s.com"
elementFormDefault="qualified">
<xsd:element name="binary-string">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="zero" type="xsd:unsignedByte" fixed="0"/>
<xsd:element name="one" type="xsd:unsignedByte" fixed="1"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Related examples in the same category