how to use restrictions and extensions in XSD simultanously

Dmitry Kulinich

Usenet Archive
Joined
Feb 19, 2007
Messages
11
Reaction score
0
Guys! I've got 1 more small problem with XSD. It simple and good, but sometimes disappointing. For example we have 3 <TH> tags - only text and 1 attribute. Then we need <restriction>-<enumeration> to set all <th>'s text values, but also <extension> to add 1 attribute How to do it simultanously inside og 1 element? Here is simple code in XSD:
<xsd:element name="TH" >

<xsd:complexType>

<xsd:simpleContent>

<xsd:extension base="xsd:string">

<!--xsd:restriction base="xsd:string">

<xsd:enumeration value="Process ID"/>

<xsd:enumeration value="Activity ID"/>

<xsd:enumeration value="Instance ID"/>

<xsd:enumeration value="Process Description"/>

</xsd:restriction-->

<xsd:attribute name="style" type="xsd:string" />

</xsd:extension>

</xsd:simpleContent>

</xsd:complexType>

</xsd:element>
 

usenet

Usenet Archive
Joined
Aug 10, 2000
Messages
1,105
Reaction score
0
For example we have 3 <TH> tags - only text and 1 attribute. Then we need <restriction>-<enumeration> to set all <th>'s text values, but also <extension> to add 1 attribute

In XSD schema you have to do it in two stages. Define the body type of the TH element (as a simple type), and then extend it to add the attribute. e.g.:

<xsd:simpleType name="THType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Process ID"/>
<xsd:enumeration value="Activity ID"/>
<xsd:enumeration value="Instance ID"/>
<xsd:enumeration value="Process Description"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="TH" >
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="THType">
<xsd:attribute name="style" type="xsd:string" /> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element>

HTH,

Pete.
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
 

usenet

Usenet Archive
Joined
Aug 10, 2000
Messages
1,105
Reaction score
0
Original Message From: "Dmitry Kulinich"
Thank you, Pete! It's really simple )))
Could you answer one more question please - how to define few <td> tags with different types (means - tags with the same name but with the different type. A've tried to set node type in restrictions but it doesn't works )

If the types are all simple types, then you can use schema's xs:union construct. e.g.:

<xs:simpleType name="TDType">
<xs:union memberTypes="xs:float xs:int xs:string"/> </xs:simpleType>

Normally you would put the most restricted type first, followed by progressively less restricted types. i.e. all integers could be represented in a string, but not all strings are valid integers.

If you want different complex types, thn I'm afraid you are out of luck with XSD schema as it is defined today!

HTH,

Pete.
 

usenet

Usenet Archive
Joined
Aug 10, 2000
Messages
1,105
Reaction score
0
Original Message From: "Dmitry Kulinich"

If the types are all simple types, then you can use schema's xs:union construct. e.g.:

<xs:simpleType name="TDType">
<xs:union memberTypes="xs:float xs:int xs:string"/>
</xs:simpleType>

Normally you would put the most restricted type first, followed by progressively less restricted types. i.e. all integers could be represented in a string, but not all strings are valid integers.

Ooops - which means I should flip xs:int and xs:float around! e.g.

<xs:simpleType name="TDType">
<xs:union memberTypes="xs:int xs:float xs:string"/> </xs:simpleType>

Just testing!!!

Pete.
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
 

usenet

Usenet Archive
Joined
Aug 10, 2000
Messages
1,105
Reaction score
0
unfortunately I needed this solution 4 the complex type anyhow, thank you very mush!!!

Then I'm afraid, as far as XSD schema is concerned, you are left with defining the superset of all the types.

Some people add schematron constraints to the XSD definition to select the correct forms at runtime, but I'm not sure many tools support that approach.

Relax-NG, an alternative schema language, has support for this sort of thing, but I'm not sure how widely supported that is either (libxml2 has some support for it).

HTH,

Pete.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top