473,320 Members | 1,841 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,320 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 3819

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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.