473,809 Members | 2,617 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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied" >
<xs:complexTy pe name="FooType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Bar"/>
</xs:sequence>
<xs:attribute name="FooAttrib ute1" type="xs:string " use="required"/>
</xs:complexType>

<xs:complexTy pe name="BarType">
<xs:attribute name="BarAttrib ute1" 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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:include schemaLocation= "BaseFooBar.xsd "/>
<xs:complexTy pe name="ExtendedB arType">
<xs:complexCont ent>
<xs:extension base="BarType">
<xs:attribute name="BarAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="ExtendedF ooType">
<xs:complexCont ent>
<xs:extension base="FooType">
<xs:attribute name="FooAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="Bar" type="ExtendedB arType"/>
<xs:element name="Foo" type="ExtendedF ooType"/>
</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 1473
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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:redefine schemaLocation= "FooBar.xsd ">
<xs:complexTy pe name="FooType">
<xs:complexCont ent>
<xs:extension base="FooType">
<xs:attribute name="FooAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="BarType">
<xs:complexCont ent>
<xs:extension base="BarType">
<xs:attribute name="BarAttrib ute2" type="xs:string "
use="required"/>
</xs:extension>
</xs:complexConte nt>
</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
4362
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
2
2597
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 this. Also, there is a KB article (http://support.microsoft.com/default.aspx?scid=kb;en-us;311318) purporting to show you how to extend the treenode to include a key. This article seems to be nearly useless to me, as (despite adding a...
4
2282
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 value="2">2</option>
3
3679
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 - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7662
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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 we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.