Hi Amy:
I find your question a bit confusing but
tolerance of ambiguity is the hallmark of the good consultant, so here is a
simple answer, based on what I think you most likely want to achieve.
Unless the business/application context
prevents you, you can add grad_address to the data
model of grad_student as a sub-element like this:
<xsd:complexType name="grad_student">
<xsd:complexContent>
<xsd:extension
base="student">
<xs:sequence>
<xs:element ref="xyz:grad_address" maxOccurs="unbounded" />
</xs:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="grade" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
This says a grad_student must have one or more
grad_addresses.
You literally extend types, not elements. But you can
have multiple levels of derivation by extension. So if you really wanted
to extend grad_address (which is already an extension of address) you could:
<xsd:complexType name="graduate_address">
<xsd:complexContent>
<xsd:extension base="grad_address">
<xsd:attribute name="address_category"
type="xsd:string"
use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="graduate_address" type="xyz:graduate_address"/>
And then use graduate_address in my first example instead of grad_address
so that you could use address_category to differentiate between campus
addresses and home addresses, for instance.
[Examples not validated]
BTW, some places follow the naming convention of adding …type
to the names of the complex types to avoid confusion with element names.
If this is not the answer you need, I will let the big guns
take over
Cheers
Jack Lindsey
From:
Amy Wong [mailto:amy_wanes@y...]
Sent: Tuesday October 31, 2006
2:59 PM
To: xml-dev@l...
Subject: extend two
elements?
Hi,
I have an element called "grad_student" which extends
"student". Now I want to extend "grad_address" element too
since "grad_student" element needs address related info.
Unfortunately I cannot merge address info from "grad_address" element
into "grad_student" element. I am wondering how I can
extend another element when this element already extends a base element?
regards,
<xsd:complexType name="grad_student">
<xsd:complexContent>
<xsd:extension base="student">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="grade" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="grad_student" type="xyz:grad_student"/>
<xsd:complexType name="grad_address">
<xsd:complexContent>
<xsd:extension base="address">
<xsd:attribute name="state" type="xsd:string" use="required"/>
<xsd:attribute name="zip_code" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="grad_address" type="xyz:grad_address"/>
Low, Low, Low Rates! Check out Yahoo! Messenger's cheap http://us.rd.yahoo.com/mail_us/taglines/postman8/*http:/us.rd.yahoo.com/evt=39663/*http:/voice.yahoo.com