I can describe a structure like this:
<element name="One" minOccurs="1" maxOccurs="1"> <complexType> <sequence> <element name="Two" type="string" minOccurs="1" maxOccurs="unbounded" /> </sequence> </complexType> </element>
It leads to:
<One> <Two>str 1</Two> <Two>str 2</Two> </One>
Also I can describe a structure like this:
<element name="One" minOccurs="1" maxOccurs="1"> <complexType> <sequence> <element name="Two" minOccurs="1" maxOccurs="unbounded"> <complexType> <attribute name="MyAttr" type="string" /> </complexType> </element> </sequence> </complexType> </element>
It leads to:
<One> <Two MyAttr="str 1" /> <Two MyAttr="str 2" /> </One>
But how to describe a structure which leads to something like this:
<One> <Two MyAttr="str 1">str 2</Two> <Two MyAttr="str 3">str 4</Two> </One>
???
Advertisement
Answer
Like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="One"> <xs:complexType> <xs:sequence> <xs:element name="Two" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="MyAttr" type="xs:string" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
the output will be
<?xml version="1.0" encoding="UTF-8"?> <One xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Two MyAttr="String">String</Two> <Two MyAttr="String">String</Two> </One>