473,508 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help extending a complex type

Hello all,

I am having a problem with extending complex types. I have a simple
base schema (FooBar.xsd) which defines XML documents of the following
form:

<Foo FooAttribute1="aaa">
<Bar BarAttribute1="xxx"/>
</Foo>

I'm trying to write a schema (ExtendedFooBar.xsd) which includes
FooBar.xsd to add one new attribute (each) to <Foo> and <Bar>.
Documents adhering to this schema should look like:

<Foo FooAttribute1="aaa" FooAttribute2="bbb">
<Bar BarAttribute1="xxx" BarAttribute2="yyy"/>
</Foo>

I can get ExtendedFooBar.xsd to validate, but XML which adheres to it
doesn't recognize the new Bar attribute. In other words, valid XML
documents are of the following form:

<Foo FooAttribute1="aaa" FooAttribute2="bbb">
<!-- Note the missing BarAttribute2 -->
<Bar BarAttribute1="xxx"/>
</Foo>

Naively, I thought that by including the base schema in the extended
one, references to 'Bar' would be satisfied by the definition in the
extended schema. This seems to be incorrect.

Here's the schema XML for the two files:

--- FooBar.xsd ---

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" >
<xs:complexType name="FooType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Bar"/>
</xs:sequence>
<xs:attribute name="FooAttribute1" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="BarType">
<xs:attribute name="BarAttribute1" type="xs:string" use="required"/>
</xs:complexType>

<xs:element name="Bar" type="BarType"/>
<xs:element name="Foo" type="FooType"/>
</xs:schema>

--- ExtendedFooBar.xsd ---

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="BaseFooBar.xsd"/>
<xs:complexType name="ExtendedBarType">
<xs:complexContent>
<xs:extension base="BarType">
<xs:attribute name="BarAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExtendedFooType">
<xs:complexContent>
<xs:extension base="FooType">
<xs:attribute name="FooAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="Bar" type="ExtendedBarType"/>
<xs:element name="Foo" type="ExtendedFooType"/>
</xs:schema>

Any help would be appreciated. I've been scouring the web and my books
for a few hours on this one.

Thanks,

Brian

Mar 20 '06 #1
2 1457
Hi Brian,

You cannot declare the same elements again, that will result in an
invalid schema. What you can do however is to redefine the two complex
types as below

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:redefine schemaLocation="FooBar.xsd">
<xs:complexType name="FooType">
<xs:complexContent>
<xs:extension base="FooType">
<xs:attribute name="FooAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="BarType">
<xs:complexContent>
<xs:extension base="BarType">
<xs:attribute name="BarAttribute2" type="xs:string"
use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Mar 21 '06 #2
Thanks for taking a look at this. I stumbled upon the same solution
yesterday, but it's nice to have it validated by someone who really
knows this stuff. I'm new to XSLT.

Brian Hartin
Pearson Educational Measurement
http://www.pearsonedmeasurement.com/
http://www.pearsonsolutions.com/

Mar 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4333
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
2
2582
by: pmcguire67 | last post by:
There has been a lot of discussion lately about extending the treeview control to allow finding a node by key rather than by index. Everyone seems to agree that a hashtable is needed to accomplish...
4
2250
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
3
3660
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types -...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.