XSD - another simple questions

M

Matthet

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?

I don't want to create second simpleType and
use it with union to first simpleType.

Thx for any help
MAciek
 
B

Bob Foster

Matthet said:
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?

There are two ways to do this. Derive a second simple type as a restriction
of the first and put the pattern there, then use the second type for the
other element, as in e2 below. Or define the second type anonymously in the
definition of the element, as in e3 below.

<xs:schema elementFormDefault="qualified" xml:lang="EN"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="t1">
<xs:restriction base="xs:string">
<xs:pattern value=".+"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="t2">
<xs:restriction base="t1">
<xs:pattern value="[0-9]*"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="e1" type="t1"/>
<xs:element name="e2" type="t2"/>
<xs:element name="e3">
<xs:simpleType>
<xs:restriction base="t1">
<xs:pattern value="[0-9]*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>

In the example, type t1 disallows empty string contents, while type t2
additionally restricts contents to the digits 0-9.

Bob Foster
http://www.xmlbuddy.com/
 
M

Matthet

"Bob Foster" wrote
...
<xs:element name="e3">
<xs:simpleType>
<xs:restriction base="t1">
<xs:pattern value="[0-9]*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>


Thanks,
I thought I tried that
but I've got problems with schema validation.

Now it works OK.

Thanks again
MAciek
 
B

Bob Foster

Matthet said:
Thanks,
I thought I tried that
but I've got problems with schema validation.

That's easy to do when you're trying out this and that variant trying to get
something to work.

If you want an excellent book on XML Schema I recommend Priscilla Walmsley's
"Definitive XML Schema". Google will find it.

Bob Foster
http://www.xmlbuddy.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top