Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extending a complexType

 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
I'm trying out the concepts given by Roger Costello (xml-schemas2.ppt p.35) about replacing the baseType content with derivedTypes, in the elements defined to be of baseType. If i understand it correctly, he says that
<xsd:complexType name="baseType" block="extension">
will not allow the derived type content to be substituted for the baseType elements.
I'm trying out this concept using an example given below -

I basically have a baseType, a derivedType, an attributeGroup (which is not relevant to this discussion), two global elements "base and jaya" and another global element "test" referring to the global "base" element.
================================================
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.today.org"
targetNamespace="http://www.today.org"
elementFormDefault="qualified">
<xsd:element name="derived" type="xsd:string"/>
<xsd:attribute name="globalAttr" type="xsd:string" use="optional"/>
<!-- Defining a baseType -->
<xsd:complexType name="baseType" block="extension">
<xsd:sequence>
<xsd:element name="base_element1" type="xsd:string"/>
<xsd:element name="base_element2" type="xsd:string"/>
</xsd:sequence>
<xsd:attributeGroup ref="baseAttrs"/>
</xsd:complexType>
<!-- This derivedType adds (element,attribute) to baseType -->
<xsd:complexType name="derivedType">
<xsd:complexContent>
<xsd:extension base="baseType">
<xsd:sequence>
<xsd:element ref="derived" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="derived" type="xsd:integer" use="optional"/>
<xsd:attribute ref="globalAttr"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!-- Defining an attribute group -->
<xsd:attributeGroup name="baseAttrs">
<xsd:attribute name="baseEnumAttr" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="enum1"/>
<xsd:enumeration value="enum2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="baseOptionalAttr" type="xsd:string"
use="optional" default="optional"/>
<xsd:attribute name="baseBoolAttr" type="xsd:boolean" fixed="false"/>
</xsd:attributeGroup>
<!-- Defining elements for substitutionGroups -->
<!-- "base" is the head element -->
<!-- xsd:element name="base" type="baseType" block="substitution"/ -->
<!-- GLOBAL elements in this schema -->
<xsd:element name="base" type="baseType"/>
<xsd:element name="jaya" substitutionGroup="base" type="derivedType"/>
<xsd:element name="test">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="base"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
=================================================
<?xml version="1.0"?>
<test xmlns="http://www.today.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.today.org
today.xsd">
<base xsi:type="derivedType">
<base_element1/>
<base_element2/>
<!-- derived/ -->
</base>
</test>
=================================================
I'm validating this stuff using Costello's xsv validator and it validates without any problem to my surprise.
My contention here is the definition -
<xsd:complexType name="baseType" block="extension">
should not make the following thing possible, i.e., trying to have a derived content for the baseType object -
<base xsi:type="derivedType">
Please rectify me for any misinterpretation of the stuff. I'm a little confused if i'm missing something here.
Thanks.
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it sure that your schema is validating in XSV. I just tried to validate your schema,using the same online tool at http://www.w3.org/2001/03/webdata/xsv
it gives an error.
PS:i validated schema only not ur instance against schema.
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was skeptical about mentioning the "use" for the global attribute. I did that deliberately expecting to see atleast a warning from the validator. My xsv validator kept calm. I figured that out. My main concern is the document instance validating without any complaints against the schema. This is as if the "block" attribute mentioned in the baseType is ineffective. Please give me any additional inputs on these lines.
Thanks.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML Spy 4.4 didn't mind the block attribute.
When I tried to validate the schema in http://www.w3.org/2001/03/webdata/xsv, I was notified that the schema validator crashed.
Cheers,
Dan
[ October 17, 2002: Message edited by: Dan Drillich ]
[ October 17, 2002: Message edited by: Dan Drillich ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan.
Seems like the validators are not caring about the block attribute. Also, i tried using the <xsd:restriction base="xsd:string"> stuff and done some restrictions to get the desired pattern as <xsd attern value="\d{1}-\d{2}"> and the validator is not at all bothered about the kind of string i supply in the instance document. I was surprised by this.
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
So that's the problem with the schema validatior and not the specs!
Rakesh.
IBM Certified XML Dev.
Mysticism is a non physical connectivity with the superior cosmic intelligence
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried validating the instance against schema using Topologi Schematron.its giving error on schema.Also i tried checking the schema using IBM schema quality checker,it also throwing error.Good!..
Error message using Topologi schematron

the use attribute in global attribute cannot be present.
Validation error:
Reason: Use of type '{http://www.today.org}derivedType' is blocked on element '{http://www.today.org}base'.
Error message using ibm schema quality checker

MESSAGE
SUBSTITUTION GROUP ERROR : the derivation method of the type of the element declaration,
element http://www.today.org:jaya, is not compatible with the type of its substitution
group head,element http://www.today.org:base [ located at file:/C:/today.xsd ]. More precisely,
this derivation method is prohibited by the value of the "block" attribute of the type
of the substitution group head.
Substitution chain :
element http://www.today.org:jaya
element http://www.today.org:base [ located at file:/C:/today.xsd ]
Originally posted by Jayadev Pulaparty:
Thanks Dan.
Seems like the validators are not caring about the block attribute. Also, i tried using the <xsd:restriction base="xsd:string"> stuff and done some restrictions to get the desired pattern as <xsd attern value="\d{1}-\d{2}"> and the validator is not at all bothered about the kind of string i supply in the instance document. I was surprised by this.

[ October 25, 2002: Message edited by: Balaji Loganathan ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balaji,
That is encouraging information. Atleast we have some law-abiding schemas I need to load them and test my concepts.
Regards,
Jayadev.
 
Niraj Sheth
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaydev,
I tried to validate your example with Xerces v2.1.0. It gave following two errors
1)[Error] today.xsd:8:68: s4s-att-not-allowed: Attribute 'use' cannot appear in element 'attribute'.
2)[Error] today.xml:7:30: cvc-elt.4.3: Type 'derivedType' is not validly derived from the type definition of element 'base'.
So that's the good news. Let me know if following statements are incorrect. If these are incorrect then I really need to go through this stuff again.It assumes the value of the 'block' or 'final' as "#all"
1) If we use 'block' attribute for a 'base' type, then we can not substitute any element with 'base' type with any element using type derived from the 'base' type. THIS DOESN'T STOP US FROM DERIVING FROM THE 'base' TYPE. It just restricts the substitution.
2) If we use 'final' attribute for a 'base' type, then we can't even derive any type from 'base' type. This will also stop us from substituting any element of 'base' type with element of any other type, because we any only substitute with element of derived type and we are not even allowed to derive any type from 'base' type.
3) If we use 'block' attribute for an element with 'base' type, the substitution restriction just applies to that element. We can still substitue other elements of 'base' type with elements with types derived from 'base'.
I would appreciate if someone can clarify the effect of applying 'final' attribute to an element.
Thanks,
Niraj
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niraj,
I'm a little busy right now with my project. I look forward to someone to answer your question. I'll get back in the night and have a cool look at it. Have a good time.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niraj Sheth
Why do you make-up your own statements instead of reading/using the w3schools statements?
http://www.w3schools.com/schema/el_complextype.asp
http://www.w3schools.com/schema/el_element.asp
http://www.w3schools.com/schema/el_schema.asp
http://www.w3schools.com/schema/el_attribute.asp
[ October 27, 2002: Message edited by: Roseanne Zhang ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic