xsd error in the following -
here xml
<?xml version="1.0" encoding="utf-8"?> <modules xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="xsdqu3.xsd"> <module code="cse1246"> <name shortname="adsa">applied data structures , algorithms</name> <level>1</level> <resourceperson> <name>anwar</name> <surname>chutoo</surname> </resourceperson> </module> <module code="cse2041"> <name shortname="web 2">web technologies ii</name> <level>2</level> <resourceperson> <fullname>shehzad jaunbuccus</fullname> </resourceperson> </module> </modules>
i'm having error @ name. resource person can either contain fullname or name , surname. please help. correctly doing part
here xsd
<?xml version="1.0" encoding="utf-8"?> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:complextype name="namensurnametype"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="surname" type="xs:string"/> </xs:sequence> </xs:complextype> <xs:complextype name="resourcepersontype"> <xs:sequence> <xs:choice> <xs:element name="namensurnametype" type="namensurnametype"/> <xs:element name="fullname" type="xs:string"/> </xs:choice> </xs:sequence> </xs:complextype> <xs:attribute name="code"> <xs:simpletype> <xs:restriction base="xs:id"> <xs:pattern value="cse(\d{4})"/> </xs:restriction> </xs:simpletype> </xs:attribute> <xs:complextype name="nametype"> <xs:simplecontent> <xs:extension base="xs:string"> <xs:attribute name="shortname" type="xs:string"/> </xs:extension> </xs:simplecontent> </xs:complextype> <xs:element name="modules"> <xs:complextype> <xs:sequence> <xs:element name="module" minoccurs="1" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="name" type="nametype"/> <xs:element name="level" type="xs:positiveinteger"/> <xs:element name="resourceperson" type="resourcepersontype"/> </xs:sequence> <xs:attribute ref="code" use="required"/> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
i can see confusion; choice "option" can particle; compositor (such xs:sequence
or xs:choice
) match description. minimum need change following definition.
<xs:complextype name="resourcepersontype"> <xs:sequence> <xs:choice> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="surname" type="xs:string"/> </xs:sequence> <xs:element name="fullname" type="xs:string"/> </xs:choice> </xs:sequence> </xs:complextype>
if want reference name seem want global complex type, 1 can create group , reference instead. below modified xsd consistent above scenario:
<?xml version="1.0" encoding="utf-8" ?> <!-- xml schema generated qtassistant/xsd module (http://www.paschidev.com) --> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:group name="namensurnametype"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="surname" type="xs:string"/> </xs:sequence> </xs:group> <xs:complextype name="resourcepersontype"> <xs:sequence> <xs:choice> <xs:group ref="namensurnametype"/> <xs:element name="fullname" type="xs:string"/> </xs:choice> </xs:sequence> </xs:complextype> <xs:attribute name="code"> <xs:simpletype> <xs:restriction base="xs:id"> <xs:pattern value="cse(\d{4})"/> </xs:restriction> </xs:simpletype> </xs:attribute> <xs:complextype name="nametype"> <xs:simplecontent> <xs:extension base="xs:string"> <xs:attribute name="shortname" type="xs:string"/> </xs:extension> </xs:simplecontent> </xs:complextype> <xs:element name="modules"> <xs:complextype> <xs:sequence> <xs:element name="module" minoccurs="1" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="name" type="nametype"/> <xs:element name="level" type="xs:positiveinteger"/> <xs:element name="resourceperson" type="resourcepersontype"/> </xs:sequence> <xs:attribute ref="code" use="required"/> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
Comments
Post a Comment