[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Elements with same name and different data type

  • From: "S, Srinivasan (Srinivasan)" <srini@l...>
  • To: xml-dev@l...
  • Date: Tue, 28 Nov 2006 19:41:47 +0530

xsd same element different type
Hi,
    I have the following XML document
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="myTesting.xsd">
	<Element>
		<Child1/>
	</Element>
	<Element>
		<Child2/>
	</Element>
</Root>

As shown above, the XML root tag in-turn contains two "element" tags which
has different child element.

I defined the schema for the above XML file as follows

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
	<xs:element name="Child1">
		<xs:complexType/>
	</xs:element>
	<xs:element name="Child2">
		<xs:complexType/>
	</xs:element>
	<xs:complexType name="ElementType1">
		<xs:sequence>
			<xs:element ref="Child1"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="ElementType2">
		<xs:sequence>
			<xs:element ref="Child2"/>
		</xs:sequence>
	</xs:complexType>

	<xs:element name="Root">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded" minOccurs="0">
				<xs:sequence minOccurs="1" maxOccurs="1">
					<xs:element name="Element"
type="ElementType1" maxOccurs="unbounded"/>
				</xs:sequence>
				<xs:sequence  minOccurs="1" maxOccurs="1">
					<xs:element name="Element"
type="ElementType2" maxOccurs="unbounded"/>
				</xs:sequence>
				<!-- Other Similar elements will go here -->
			</xs:choice>
		</xs:complexType>		
	</xs:element>
</xs:schema>

I validated XML document with XMLSpy and the document is valid as per the
schema.

When I try to validate the XML document using Xerces, I got the following
error.
"Multiple elements with name 'Element', with different types, appear in the
model group"

With the above error message, It looks like the XML schema file is not
valid. But I am not sure how XMLSpy is
validating this file successfully

Thanks,
Srini.



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.