Mega Code Archive

 
Categories / XML / XML Schema
 

Use choice to define elements with random number and occurence

File: Data.xml <?xml version="1.0"?> <binary-string xmlns="http://www.rntsoft.com"            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:schemaLocation="http://www.rntsoft.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.rntsoft.com"             xmlns="http://www.rntsoft.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>