469,353 Members | 2,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

how to use restrictions and extensions in XSD simultanously

Guys! I've got 1 more small problem with XSD. It simple and good, but
sometimes disappointing.
For example we have 3 <THtags - only text and 1 attribute.
Then we need <restriction>-<enumerationto set all <th>'s text values, but
also <extensionto 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>
--
Thank you,
De Cool,
EPE
Feb 19 '07 #1
5 11766
On 19 Feb, 21:48, "Dmitry Kulinich" <d...@isd.dp.uawrote:
For example we have 3 <THtags - only text and 1 attribute.
Then we need <restriction>-<enumerationto set all <th>'s text values, but
also <extensionto 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)
=============================================

Feb 20 '07 #2
Original Message From: "Dmitry Kulinich"
>
Thank you, Pete! It's really simple )))
Could you answer one more question please - how to define few <tdtags 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.
--
=============================================
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)
=============================================

Feb 20 '07 #3
On 20 Feb, 15:29, use...@tech-know-ware.com wrote:
Original Message From: "Dmitry Kulinich"
Thank you, Pete! It's really simple )))
Could you answer one more question please - how to define few <tdtags 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.
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)
=============================================

Feb 20 '07 #4
unfortunately I needed this solution 4 the complex type
anyhow, thank you very mush!!!
<us****@tech-know-ware.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
On 20 Feb, 15:29, use...@tech-know-ware.com wrote:
>Original Message From: "Dmitry Kulinich"
Thank you, Pete! It's really simple )))
Could you answer one more question please - how to define few <tdtags
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.

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)
=============================================

Feb 21 '07 #5
On 21 Feb, 08:31, "Dmitry Kulinich" <d...@isd.dp.uawrote:
unfortunately I needed this solution 4 the complex type
anyhow, thank you very mush!!!
Original Message From: "Dmitry Kulinich"
Thank you, Pete! It's really simple )))
Could you answer one more question please - how to define few <tdtags
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 )
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.
--
=============================================
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)
=============================================

Feb 21 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tom Dearst | last post: by
2 posts views Thread by Shailendra Batham | last post: by
6 posts views Thread by Jess | last post: by
1 post views Thread by Paul van Brouwershaven | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.