olympic.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="olympic"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="1" name="result"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="1" ref="country"/> </xs:sequence> <xs:attributeGroup ref="result1"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="country"> <xs:complexType> <xs:attributeGroup ref="country1"/> </xs:complexType> </xs:element> <xs:attributeGroup name="result1"> <xs:attribute name="year" type="xs:integer" use="required"/> <xs:attribute name="city" type="xs:string" use="required"/> </xs:attributeGroup> <xs:attributeGroup name="country1"> <xs:attribute name="code" type="xs:string" use="required"/> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="rank" type="xs:integer" use="required"/> <xs:attribute name="gold" type="xs:integer" use="required"/> </xs:attributeGroup> </xs:schema>
olympic.xml
<?xml version="1.0" encoding="UTF-8"?> <olympic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="olympic.xsd"> <result year="2008" city="beijing"> <country name="China" rank="1" code="CHN" gold="51"/> </result> </olympic>