You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Roger L. Costello" <co...@mitre.org> on 2000/09/03 19:00:25 UTC
XML Schemas: deriving by extension from a user-defined simpleType
Hi Folks,
I have a question about deriving by extension from a user defined
simpleType.
Suppose that I would like to create a schema for this:
<cost currency="USD">41.95</cost>
Here is one approach:
<element name="cost">
<complexType base="decimal" derivedBy="extension">
<attribute name="currency" type="string" use="required"/>
</complexType>
</element>
The disadvantage of this approach is that it allows <cost> to contain
any decimal value. Suppose that we want to restrict it to contain a
decimal value with no more than two digits to the right of the decimal
point. Here is a simpleType to define a restricted decimal:
<simpleType name="money" base="decimal">
<scale value="2"/>
</simpleType>
Now, let me modify the above cost declaration to reference this new
type:
<element name="cost">
<complexType base="t:money" derivedBy="extension">
<attribute name="currency" type="string" use="required"/>
</complexType>
</element>
(Let's assume that "t" has been set to the targetNamespace)
Is this second version of cost legal? Can we derive (by extension) from
a user defined simpleType?
I have found that the Apache 1.2 parser does not accept the second
version, whereas it does accept the first version. /Roger
XML Schemas: Regular Expression Question
Posted by "Roger L. Costello" <co...@mitre.org>.
Hi Folks,
Consider this regular expression:
(.)+\.(gif|jpg|jpeg|bmp)
As I interpret this regular expression it says, "one or more occurrences
of any character, followed by a dot, followed by either gif or jpg or
jpeg or bmp". Correct?
Here's my question - why is it that two schema validators (Oracle and
xerces 1.2) both accept the following strings:
images\mighty_oj.gif
images\omega.jpg
images\wheateena.jpg
but reject these strings:
images\champion.gif
images\greenPower.jpg
images\juiceman.jpg
Both schema validators generate an error, reporting that the strings are
"invalid text". Am I missing something obvious? Why are these strings
invalid? (Are xerces and Oracle using the same regular expression
parser?) Below is the actual XML Schema and instance document for those
interested. /Roger
XML Schema
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/1999/XMLSchema"
targetNamespace="http://www.test.org"
elementFormDefault="qualified"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation=
"http://www.w3.org/1999/XMLSchema
http://www.w3.org/1999/XMLSchema.xsd"
xmlns:t="http://www.test.org">
<element name="images">
<complexType>
<sequence>
<element name="image" type="t:imageType"
maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<simpleType name="imageType" base="string">
<pattern value="(.)+\.(gif|jpg|jpeg|bmp)"/>
</simpleType>
</schema>
Instance Document
<?xml version="1.0"?>
<images xmlns ="http://www.test.org"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:schemaLocation="http://www.test.org
test.xsd">
<image>images\mighty_oj.gif</image>
<image>images\champion.gif</image>
<image>images\greenPower.jpg</image>
<image>images\juiceman.jpg</image>
<image>images\omega.jpg</image>
<image>images\wheateena.jpg</image>
</images>