473,789 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Schema: error with restriction in simpleContent

Hello!

In my schema I have the following:

<xs:complexTy pe name="textareaT ype">
<xs:simpleConte nt>
<xs:restricti on base="xs:string ">
<xs:attribute ref="label" use="required" />
</xs:restriction>
</xs:simpleConten t>
</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 <restrictiono r
<extensionmus t 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 3855

Kai Schlamp <st***********@ gmx.dewrote in
<11************ *********@50g20 00hsm.googlegro ups.com>:
<xs:complexTy pe name="textareaT ype">
<xs:simpleConte nt>
<xs:restricti on base="xs:string ">
<xs:attribute ref="label" use="required" />
</xs:restriction>
</xs:simpleConten t>
</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 <restrictiono r <extensionmus t 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************ **********@o38g 2000hse.googleg roups.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="textareaT ype"/>
<xs:attribute name="label" type="xs:string "/>
<xs:complexTy pe name="textareaT ype">
<xs:simpleConte nt>
<xs:extension base="str-10-chr">
<xs:attribute ref="label" use="required"/>
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
<xs:simpleTyp e name="str-10-chr">
<xs:restricti on 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>mor e 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">mor e 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;1 0 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
2726
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 is a subset of the other. I will describe one part of the schema to give you an idea of what my problem is. The "big" schema calls for 0 or more selector elements, each containing a (required) name attribute and simple character data, as...
4
2936
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 defined in a different namespace from the element.
0
1130
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 the schema below, the parser keeps on finding an error at line <in:extension base="pageRange"> The same schema validates ok when the conventional xs: namespace is used.
2
4194
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" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/, are causing trouble. I tried to create schema using xmlspy and I get an error saying name "b:dt" cannot have a namespace prefix. I am new to xml. Can somebody please help with schema. <appointments> <appointment>
1
408
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 base="LatitudeType"> <xs:attribute name="Units" type="LatLonUnitsType" use="required" /> </xs:extension>
1
1991
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 than a plain vanilla schema, but doesn't strike me as obscenely complex. Are there general rules for what can an can not be mapped between any XSD schema & a .net DataSet? Thanks
2
2819
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 get right. I didn't design the schema and to tell the truth, most of it is beyond my rudimentary understanding of XML. So far, the main problem I've run into is the simpleType below: <simpleType name="VariableName">
1
3053
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 base="xs:positiveInteger"/> </xs:simpleType>
0
2632
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 the particle of the base this xsd file is valid as per w3c standard i am also providing error in detail and geometry.xsd file geometry.xsd <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://www.opengis.net/gml"...
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10142
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
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.