Reputation: 65
In my scenario my XSD should have multiple groups under one root tag, #XSD#
<xs:group name="location">
<xs:sequence>
<xs:element name="city" type="xs:string"/>
<xs:element name="flat_num" type="xs:string"/>
<xs:element name="landmark" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
</xs:sequence>
</xs:group>
<xs:group name="student">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="mothername" type="xs:string"/>
<xs:element name="fathername" type="xs:string"/>
</xs:sequence>
</xs:group>
<xs:element name="Student_details" type="details"/>
<xs:complexType name="details">
<xs:group ref="location"/>
<xs:group ref="student"/>
</xs:complexType>
</xs:schema>
When i am validating with xml , it says this format is wrong , can any one help to let me know how to create multiple groups
Upvotes: 2
Views: 564
Reputation: 5973
Your missing the Sequence in the complex type
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2017 - Developer Bundle Edition (Trial) 15.0.0.7089 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:group name="location">
<xs:sequence>
<xs:element name="city" type="xs:string" />
<xs:element name="flat_num" type="xs:string" />
<xs:element name="landmark" type="xs:string" />
<xs:element name="street" type="xs:string" />
</xs:sequence>
</xs:group>
<xs:group name="student">
<xs:sequence>
<xs:element name="firstname" type="xs:string" />
<xs:element name="lastname" type="xs:string" />
<xs:element name="mothername" type="xs:string" />
<xs:element name="fathername" type="xs:string" />
</xs:sequence>
</xs:group>
<xs:element name="Student_details" type="details" />
<xs:complexType name="details">
<xs:sequence>
<xs:group ref="location" />
<xs:group ref="student" />
</xs:sequence>
</xs:complexType>
</xs:schema>
I would also question whether a group best implements what you are trying to describe. What you have currently will produce XML like this
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2017 - Developer Bundle Edition (Trial) 15.0.0.7089 (https://www.liquid-technologies.com) -->
<Student_details xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Schema.xsd">
<city>string</city>
<flat_num>string</flat_num>
<landmark>string</landmark>
<street>string</street>
<firstname>string</firstname>
<lastname>string</lastname>
<mothername>string</mothername>
<fathername>string</fathername>
</Student_details>
Upvotes: 2