473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Schema: error with restriction in simpleContent

Hello!

In my schema I have the following:

<xs:complexType name="textareaType">
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:attribute ref="label" use="required" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>

But W3C Schema validator tells me there is an error (derivation of
complex type by restriction of simple type not allowed), even if
w3schools writes, that this should be valid code (http://
http://www.w3schools.com/schema/sche...plex_text.asp).
I also checked the original Schema reference (http://www.w3.org/TR/
xmlschema-1/), that points out: "Note that either <restrictionor
<extensionmust be chosen as the content of <simpleContent>."
When I replace restriction by extension everything works fine. But I
want to restrict the element type in a further step.
Any help?

Best regards,
Kai

Oct 31 '07 #1
3 3821

Kai Schlamp <st***********@gmx.dewrote in
<11*********************@50g2000hsm.googlegroups.c om>:
<xs:complexType name="textareaType">
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:attribute ref="label" use="required" />
</xs:restriction>
</xs:simpleContent>
</xs:complexType>

But W3C Schema validator tells me there is an error
(derivation of complex type by restriction of simple type
not allowed),
Guess what? They're right.
even if w3schools writes, that this should be valid code
(http://www.w3schools.com/schema/sche...plex_text.asp).
I'm of very low opinion of w3schools in general, but in this
case they don't assert anything of the sort. They just
didn't mention that a complex type may not be a restriction
of a simple type.
I also checked the original Schema reference
(http://www.w3.org/TR/ xmlschema-1/), that points out:
"Note that either <restrictionor <extensionmust be
chosen as the content of <simpleContent>."
You should've checked 2.2.1.3 as well.

Since you forgot to mention what it is that you're trying to
achieve, I'll refrain from giving any further advice.

--
"I can't help but wonder if you... don't know a hell of a
lot more about practically every subject than Solomon ever
did."
Nov 1 '07 #2
Hy Pavel,

thanks for the answer.
I just want to scheme a simple xml tag like this
<mytag myattr="10">foo</mytag>
and want to restrict "foo" to the length of 10 characters, thats all.
But I didn't find an example on the web for doing such an restriction
in this case (I am pretty new to XML, but I think you already know
that ;-))
As I understand the mytag must be a complex type, cause it has an
attribute ("myattr") and a content ("foo").
What's the best way to achieve this?

Nov 1 '07 #3

Please quote what you're replying to.

Kai Schlamp <st***********@gmx.dewrote in
<11**********************@o38g2000hse.googlegroups .com>:
I just want to scheme a simple xml tag like this
<mytag myattr="10">foo</mytag>
and want to restrict "foo" to the length of 10 characters,
thats all. But I didn't find an example on the web for
doing such an restriction in this case (I am pretty new to
XML, but I think you already know that ;-))
As I understand the mytag must be a complex type, cause it
has an attribute ("myattr") and a content ("foo").
What's the best way to achieve this?
Well, restrict then extend.

pavel@debian:~/dev/schema$ a schema.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="textarea" type="textareaType"/>
<xs:attribute name="label" type="xs:string"/>
<xs:complexType name="textareaType">
<xs:simpleContent>
<xs:extension base="str-10-chr">
<xs:attribute ref="label" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="str-10-chr">
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
pavel@debian:~/dev/schema$ for F in sch*.xml ; do
xmllint --schema schema.xsd $F ; echo ; done
<?xml version="1.0"?>
<textarea>more than 10 characters</textarea>
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': The attribute 'label' is required but
missing.
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': [facet 'maxLength'] The value has a
length of '23'; this exceeds the allowed maximum length
of '10'.
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': 'more than 10 characters' is not a
valid value of the atomic type 'str-10-chr'.
sch1.xml fails to validate

<?xml version="1.0"?>
<textarea label="aaa">more than 10 characters</textarea>
sch2.xml:1: element textarea: Schemas validity error :
Element 'textarea': [facet 'maxLength'] The value has a
length of '23'; this exceeds the allowed maximum length
of '10'.
sch2.xml:1: element textarea: Schemas validity error :
Element 'textarea': 'more than 10 characters' is not a
valid value of the atomic type 'str-10-chr'.
sch2.xml fails to validate

<?xml version="1.0"?>
<textarea>&lt;10 chars</textarea>
sch3.xml:1: element textarea: Schemas validity error :
Element 'textarea': The attribute 'label' is required but
missing.
sch3.xml fails to validate

<?xml version="1.0"?>
<textarea label="aaa">&lt;10 chars</textarea>
sch4.xml validates

pavel@debian:~/dev/schema$

I heartily recommend reading W3C's XML Schema Primer. It
might take you a day or two, but will give you a solid
understanding of the basics.

--
"I can't help but wonder if you... don't know a hell of a
lot more about practically every subject than Solomon ever
did."
Nov 1 '07 #4

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

Similar topics

1
by: Gregg Williams | last post by:
Hi--I am having a problem designing a schema to fit my XML data, and I'm hoping that someone can help. Essentially, I have a schema in mind and two target vocabularies for it, where one vocabulary...
4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
0
by: Ingrid | last post by:
I am trying to create a schema with my own namespace/prefix "in:" instead of xs: (to be able to import it into a different schema afterwards) - but can't seem to make it work. Trying to validate...
2
by: M Rao | last post by:
I have xml data coming in as a stream from a web service running against exchange server.The attributes for the elements dtstart and dtend, b:dt="dateTime.tz"...
1
by: shakuf | last post by:
hi i would like to define a type with restrictions, i used the following schema but i get an error <xs:element name="Latitude"> <xs:complexType> <xs:simpleContent> <xs:extension...
1
by: David Laub | last post by:
The following valid XSD schema can NOT be successfully read by the ReadXMLSchema method of the DataSet object - it errors out with a "NonEmptyString not defined" error. This schema is more complex...
2
by: Chuck Bowling | last post by:
AIML Schema: http://209.168.21.76/CommunityStarterKit/Downloads/258.aspx I have a Schema (in the link above) that I've been trying to make work in VS2003 for a while now and just can't seem to...
1
by: Blue Doze | last post by:
Hello, I have the following XML schema fragment: <xs:complexType name="type.1"> <xs:simpleContent> <xs:restriction base="ns:type"> <xs:simpleType> <xs:restriction...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.