473,659 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to do simple type extension with restriction?

I have a simple type like this:

<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>

Now, I need to have an id attribute to that, so I'm trying to make it a
complex type by extending to

<xs:complexTy pe name="SizeType" >
<xs:simpleConte nt>
<xs:extension base="xs:token" >
....
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

Now, I'm stuck. How do I change that to a complex type, with the enumeration
there? Better, is there a way to give an id to a simpleType, without
changing it
to a complexType, as the complexType is, er..., complex for such simple
thing?

TIA.
Jul 20 '05 #1
4 2655


scorpion wrote:
I have a simple type like this:

<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>

Now, I need to have an id attribute to that, so I'm trying to make it a
complex type by extending to

<xs:complexTy pe name="SizeType" >
<xs:simpleConte nt>
<xs:extension base="xs:token" >
....
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

Now, I'm stuck. How do I change that to a complex type, with the
enumeration
there? Better, is there a way to give an id to a simpleType, without
changing it
to a complexType, as the complexType is, er..., complex for such simple
thing?


As soon as you want an element to have an attribute you need a complex
type for it, you can only use a simple type if the element has only text
data as its content and no child elements and no attributes.
As for your example it is not quite clear what you want to have, if you
want to have an element with its content being of your SizeType and an
additional ID attribute then the schema is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>

<xs:complexTy pe name="SizeIdTyp e">
<xs:simpleConte nt>
<xs:extension base="SizeType" >
<xs:attribute name="id" type="xs:ID" />
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

<xs:element name="size" type="SizeIdTyp e" />

</xs:schema>

and an example document is

<?xml version="1.0" encoding="UTF-8"?>
<size xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040424Xs d.xml"
id="theSize">me dium</size>

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:


As soon as you want an element to have an attribute you need a complex
type for it, you can only use a simple type if the element has only text
data as its content and no child elements and no attributes.
As for your example it is not quite clear what you want to have, if you
want to have an element with its content being of your SizeType and an
additional ID attribute then the schema is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>

<xs:complexTy pe name="SizeIdTyp e">
<xs:simpleConte nt>
<xs:extension base="SizeType" >
<xs:attribute name="id" type="xs:ID" />
</xs:extension>
</xs:simpleConten t>
</xs:complexType>

<xs:element name="size" type="SizeIdTyp e" />

</xs:schema>

and an example document is

<?xml version="1.0" encoding="UTF-8"?>
<size xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040424Xs d.xml"
id="theSize">me dium</size>


Thanks, I got it.

Is there any reason why attributes are not allowed on simpleType?
There are a lot of cases where I can have very simple schema
if I can have attributes directly on simpleType.
Jul 20 '05 #3


scorpion wrote:
Is there any reason why attributes are not allowed on simpleType?
There are a lot of cases where I can have very simple schema
if I can have attributes directly on simpleType.


If XML schema only used types to type element content it might make
sense but you can also type attributes and what should be the meaning of
a schema where a simple type is defined which includes an attribute and
then that type is assigned to an attribute elsewhere? Clearly there
needs to be a distinction between types that can be applied to
attributes and elements (which are the simple types) and those types
that can only be applied to elements (which are the complex types)
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
scorpion <sc******@dev.n ull> writes:
Is there any reason why attributes are not allowed on simpleType?
There are a lot of cases where I can have very simple schema
if I can have attributes directly on simpleType.


If you defined a simple type T as taking the
attributes foo (integer) and bar (string), what
would / should happen when you declare an
attribute as having type T?

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7109
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the "Russian doll" style of schema design, where the nested type is local and anonymous (not a separate global type). 2. A complex type has nested within it a simple type which is derived through restriction with at least one facet, again nested,...
3
1507
by: Matthet | last post by:
Hello I've got simpleType restricted by pattern one element uses this simpleType and I would like another element to use this SimpleType but with one extra pattern. How to do it?
0
1631
by: Fender Mussel | last post by:
Hi all, Is it possible to check the content of a mixed type? I would like to define an enumeration for it. The following example works syntactically, but XMLSpy does no checks on the content at all: <xsd:simpleType name="my_enum_type"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="enum1"/> <xsd:enumeration value="enum2"/>
4
2545
by: Daniel Frey | last post by:
Hello, Maybe you know howto. I want to have an element which takes a subelement. Depending on an attribute within this subelement, a second subelement may have different attributes allowed: 001 <Service> 002 <Header Kind="1"/> 003 <Input Data="asdasd"/> 004 </Service>
2
1413
by: Brett Gerhardi | last post by:
Hi all, I'm trying to something that I'm sure must be possible within the schema language but I cannot seem to work it out. Briefly, I am defining a multi-tiered base structure - each tier has its own complextype defined with a base CT having the structure that others should follow. At the leaf ends of some areas I want to restrict the type of elements that are defined in restriction extended types but cannot find the correct way to...
3
510
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of course, the generated proxy is not the same). When I am looking at the C++ generated code, it seems fine, but when I am executing the code, I always get the first choice type.
9
2506
by: Kanchana D S | last post by:
Hi, I have a complex type which has to have its content in the xml instance document as shown below : <CONFIG_INFO> <country resourceNumber="20004" fieldSecurity="5, 5">Great Britain</label> </CONFIG_INFO>
1
1773
by: Jiho Han | last post by:
I have a type in a schema: <xs:complexType name="SimpleExt"> <xs:simpleContent> <xs:extension base="xs:int"> <xs:attribute name="name" type="xs:string" /> </xs:extension> </xs:simpleContent> </xs:complexType>
1
1278
by: Nick Bassiliades | last post by:
Hi everybody, I would like to ask a very specific question about how I can re-define an enumerated attribute type. Specifically, I have two XML Schema files. In file A I have the following attribute group declaration: *********** file A ****************** <xs:attributeGroup name="kind.attrib">
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.