• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

problem with schemas

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I was going through Roger L. Costello's slides on schemas. While talking about derivation by restriction, he mentions on slide 100:
'If the base type has an element with minOccurs="0", and the subtype wishes to
not have that element, then it can simply leave it out.'
Does it mean that only those elements which have a minOccurs="0" can be omitted in types derived by restriction?
I tried it by creating a pair of xml and xsd files and omitted some elements of the base type at random and the resulting xsd file was okayed by XSV.
My confusion is if any element can be deleted from the base type just by omission from the derived type, then why did Costello put that condition of 'minOccurs="0"' in his statement? Or did I just read too much between the lines?
I'm including the xml and xsd files:
XML file:
<?xml version="1.0"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
<some-elem>
<elem1>this is elem1</elem1>
<elem2>10</elem2>
<elem3>this is elem3</elem3>
</some-elem>
</test>
Schema file:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:complexType name="baseType">
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
<xs:element name="elem2" type="xs:integer"/>
<xs:element name="elem3" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="derived">
<xs:complexContent>
<xs:restriction base="baseType">
<xs:sequence>
<xs:element name="elem1" type="xs:string"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element name="some-elem" type="baseType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Any help would be greatly appreciated.
Thanks,
Dhananjay
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dhananjay,
I would like to point out something in your Schemal file. The Following Element declaration still pointing to “baseType” not to “derived” type.

Second thing I noticed here that your XML file is valid it has all the contents according to “baseType” definition.

I really don’t see any involvement of “derived” type any where except its declaration in Schema File. Try to do following changes and see, I am not sure about my suggestion still u can try.


Please do post your findings here. We are also try to learn.


I would love to play around with your files and try to find/learn something here but I don’t have setup here on this PC.

Thanks
[ February 08, 2003: Message edited by: Vivek Saxena ]
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vivek is correct.

Try this one, I got the error message
 
Dhananjay Goswami
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am extremely sorry for having drifted away from the thread for some time but there was some enormous work pressure which kept me away.
Thanks a lot to both of you, Roseanne and Vivek for your responses.
Anyways, now I've gone through your messages and done some playing around with those files.
Roseanne, the error message is there because in the schema <some-elem> is declared to be a 'derived' type and in that version, it doesn't have the elem3 according to your xsd. That would've given an error in any case.
We are trying to substitute "basetype" with
"derived". So, I had intentionally kept the <some-elem> in my xml file as "basetype" since you can substitute a basetype with derived type and not vice-versa.
Vivek, if the schema is wrong, then the validation should have failed. So, whether "derived" was used in the xml file is not quite relevant. The validation shouldn't have taken place since the derivation itself was incorrect according to what I've understood.
Now, since a validator like xsv is also validating this thing, I've started thinking that maybe 'minOccurs="0"' is not an important consideration and you can probably leave out whatever you want from the base type when creating a derived type by restriction of a complex base type.
I hope I've been able to explain myself clearly.
Thanks (hoping you guys are still interested in this thread)
Dhananjay
 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please follows my observation and hopefully you would agree that what ever is �roger� is saying is correct.
Example # 1



When I tried to validate, I got following message and which means that file is valid.

Example # 2



When I tried to validate, I got following message and which means that file is not valid. If we see the error message, it is very much clear.

Example # 3



When I tried to validate, I got following message and which means that file is valid.


What I am trying to say is that you can�t just remove any element form the �derived�. It must have �minOccurs="0" �.

If I can be of further assistance, please let me know.
Thanks
Vivek
 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to say one more thing that in order to see actual implementation of �derived� type you have to use it in your �Schema� file not just declare it. Your XML file is not validated against the �derived� type till you use (assign to some element) it. In your case you just have declared a �derived� type but still you are you are using �basetype�. That is why your XML file is valid since it does not validate against the definition of �derived� type, XML file simple validated against the �basetype� definition.
I hope I am able to put my point here.
Thanks
vivek
 
Dhananjay Goswami
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek,
Thanks for trying out so much to help me solve this problem.
Well, I tried to validate the xml file using the schema that you had supplied along with it in your example # 2 with XSV. It validates this xml file just fine. This is the success message that I got from XSV:
D:\XML Schema\xml-schemas\labs\lab06>xsv test.xml
<?xml version='1.0'?>
<xsv docElt='{None}test' instanceAssessed='true' instanceErrors='0' rootType='[Anonymous]' schemaErrors='0' schemaLocs='None -> test.xsd' target='file:/D:/XML Schema/xml-schemas/labs/lab06/test.xml' validation='strict' version='XSV 1.204/1.109 of 2001/10/03 21:06:42' xmlns='http://www.w3.org/2000/05/xsv'>
<schemaDocAttempt URI='file:/D:/XML Schema/xml-schemas/labs/lab06/test.xsd' outcome='success' source='schemaLoc'/>
</xsv>
So, probably its a bug with xsv. Which parser are you using?
Thanks,
Dhananjay
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic