• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

override an attribute from parent element?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, there:

I have two elements with corresponding complex types, student and grad_student. grad_student extends student which has an required attribute called "salary". Now if I I want to make "salary" attribute "optional" in for grad_student, how can I do that?

<xsd:complexType name="student">
<xsd:complexContent>
<xsd:extension base="xyz:person">
<xsd:attribute name="sid" type="xsd:ID" use="required"/>
<xsd:attribute name="salary" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="student" type="xyz:student"/>
<xsd:complexType name="grad_student">
<xsd:complexContent>
<xsd:extension base="xyz:student">
<xsd:attribute name="s_name" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="grad_student" type="xyz:grad_student"/>



The following fails since salary is inherited and cannot be declared in the
child element again:

<xsd:complexType name="student">
<xsd:complexContent>
<xsd:extension base="xyz:person">
<xsd:attribute name="sid" type="xsd:ID" use="required"/>
<xsd:attribute name="salary" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="student" type="xyz:student"/>
<xsd:complexType name="grad_student">
<xsd:complexContent>
<xsd:extension base="xyz:student">
<xsd:attribute name="s_name" type="xsd:string" use="optional"/>
<xsd:attribute name="salary" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="grad_student" type="xyz:grad_student"/>



regards,
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jack,

Am not sure if you can override an attribute like that, but your requirement can be achieved in almost a similar way as yours but with an additional type.

Find the below given sample XSD which suits your requirement :



Sample XML for the above XSD :



In the xml you can observe the element grad_student, the first occurrence has the salary attribute where as the second doesn't.

Regards,
Srivatsa Katta
 
Jack Wanes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that may be the only way to solve this problem as I thought?
 
permaculture is giving a gift to your future self. After reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic