Validation against simpleTypes from an instance doc?

P

Porthos

I'm fairly certian that I can't do what I'm about to ask, but here
goes. I have a schema document in which a dozen different simpleTypes
have been declared. Each simple type restricts xsd:integer in some
ways (value, number of characters, etc). This schema document is
regularly referenced in conjunction with a second schema where elements
are defined with the simpleTypes as their 'type'.

I want to write an XML instance document to validate against the
simpleType schema document to verify that the simpleTypes are written
correctly (i.e. that they appropriatly restrict xsd:integer). I only
want to modify the schema document to include elements as a last
resort. Is there a way to do this?

I haven't had any luck with trial and error. Likewise, I've been
searching the web and pouring over the W3C spec to see if there is a
way to do this or not. Either I'm not looking in the right places or
this is just not possible. Your comments would be appreciated.

--Porthos
 
H

Henry S. Thompson

Use xsi:type.

For example,

simp.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/banana">
<xs:simpleType name="oddNums">
<xs:restriction base="xs:integer">
<xs:pattern value=".*[13579]"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

test.xml:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://www.example.org/banana"
xsi:schemaLocation="http://www.example.org/banana simp.xsd">
<good xsi:type="b:eek:ddNums">17</good>
<bad xsi:type="b:eek:ddNums">18</bad>
</root>

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
M

Martin Honnen

Porthos wrote:

I want to write an XML instance document to validate against the
simpleType schema document to verify that the simpleTypes are written
correctly (i.e. that they appropriatly restrict xsd:integer).

If you want to check a schema for correctness then you can do that
without having an instance document, most parsers allow you to "compile"
a schema and check it for correctness in that process and give you
errors about thes schema. There is also a schema for schemas against
which you can validate your schema although I have seen parsers choke on
that meta schema.
 

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

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top