I have xml file like this
<?xml version="1.0" encoding="UTF-8"?>
<specification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file://Desktop/normal.xsd">
<university>
<refstr>bdvl_te_skrm_stc</refstr>
<ref_complete_customer path="/work/bsr.xml"/>
<Code>A0f11478</Code>
<Area>sku</Area>
<started>1987</started>
<branch>
<electronics>
<students Nr="120" ece="ab">
<student Name="svr" year="2010" rank="3"/>
<student Name="bvr" year="2010" rank="1"/>
</students>
</electronics>
</branch>
<semister>
<semister num="3"/>
<extrainfo/>
</semister>
<address>
<extrainfo> some data.
</extrainfo>
</address>
</university>
</specification>
genarated xsd schema for this xml file is
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wmh="http://www.wmhelp.com/2003/eGenerator" elementFormDefault="qualified">
<xs:element name="specification">
<xs:complexType>
<xs:sequence>
<xs:element ref="university"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="university">
<xs:complexType>
<xs:sequence>
<xs:element ref="refstr"/>
<xs:element ref="ref_complete_customer"/>
<xs:element ref="Code"/>
<xs:element ref="Area"/>
<xs:element ref="started"/>
<xs:element ref="branch"/>
<xs:element ref="semister"/>
<xs:element ref="address"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="refstr" type="xs:string"/>
<xs:element name="ref_complete_customer">
<xs:complexType>
<xs:attribute name="path" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="Code" type="xs:string"/>
<xs:element name="Area" type="xs:string"/>
<xs:element name="started" type="xs:string"/>
<xs:element name="branch">
<xs:complexType>
<xs:sequence>
<xs:element ref="electronics"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="electronics">
<xs:complexType>
<xs:sequence>
<xs:element ref="students"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="students">
<xs:complexType>
<xs:sequence>
<xs:element ref="student" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Nr" type="xs:string" use="required"/>
<xs:attribute name="ece" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="student">
<xs:complexType>
<xs:attribute name="Name" type="xs:string" use="required"/>
<xs:attribute name="year" type="xs:string" use="required"/>
<xs:attribute name="rank" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="semister">
<xs:complexType>
<xs:sequence>
<xs:element ref="semister"/>
<xs:element ref="extrainfo"/>
</xs:sequence>
<xs:attribute name="num" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="extrainfo" type="xs:string"/>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element ref="extrainfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
but when I validate this type of xml it gives error like this
“element university{} has invalid structure for schema definition. this error showing at “address element” in the university node.”
I am not able to rectify this error, can any one tell me how to modify this error.What should I change in the schema. when I validate schema it has no errors.
Thanks in advance.
If I run your XML through validation with the provided XML Schema, I don’t see any problem with the
addresselement. However, in your schema thesemisterelement definition refers to itself. Since it doesn’t specify minimal occurrences, the default is gonna be 1. This effectively creates an infinitely recursive requirement. Consider changing your XML Schema like this…Or whatever seems like an appropriate constraint that doesn’t force an infinite recursion.