Rank: Newbie
Joined: 5/11/2009 Posts: 2 Location: Riga
|
Hi, All !
I am new to Schema and xml and I am very confused by the topic of "Derivation by restriction"
1) Somewhere in books I've seen phrase: "It allows change derived elements *automatically* if base element is changed".
Good ! But, alas, when I use restriction on complex type, I need to copy/paste text of base type (adding "restriction base" clause) and then make allowed restrictions on that copy. Thus, what miracle could change my "copied text" in restricted element when base element (text) is changed ? As I see it, only consequences of changing base type would be that restricted type could stop validating if it "goes outside" of base class
2) It seems that XMLSpy validates everything in restricted type not taking into account what is base type is. For example: ================================================= <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="BaseUnr"> <xs:sequence> <xs:element name="e1mandatory" type="xs:decimal" maxOccurs="3"/> <xs:element name="e2mandatory" type="xs:decimal" maxOccurs="3"/> <xs:element name="e1optional" type="xs:decimal" minOccurs="0" maxOccurs="3"/> <xs:element name="e2optional" type="xs:decimal" minOccurs="0" maxOccurs="3"/> </xs:sequence> </xs:complexType> <xs:complexType name="Restricted"> <xs:complexContent> <xs:restriction base="BaseUnr"> <xs:sequence> <xs:element name="e2mandatory" type="xs:string" maxOccurs="3"/> <xs:element name="e1optional" type="xs:decimal" minOccurs="0" maxOccurs="3"/> <xs:element name="e1additional" type="xs:dateTime" minOccurs="0" maxOccurs="3"/> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:schema> ================================================= validates although it should't because I took away "e1mandatory", changed type of "e2mandatory" and added "e1additional" to base type "BaseUnr"
I am using XMLSpy professional v5.3, could it be the reason ?
|
Rank: Newbie
Joined: 10/28/2002 Posts: 1,283 Location: AT
|
Hi UldisUlmanis,
this is an invalid restriction. I would recommend using the latest version of XML Spy (2009sp1) . The validator in the latest version has significant improvements over version 5.3 which was released over 5 years ago. In 2009 your schema is invalid.
|