Validation against simpleTypes from an instance doc?

Discussion in 'XML' started by Porthos, Nov 2, 2005.

  1. Porthos

    Porthos Guest

    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
     
    Porthos, Nov 2, 2005
    #1
    1. Advertising

  2. 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:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
     
    Henry S. Thompson, Nov 3, 2005
    #2
    1. Advertising

  3. 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 3, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wallace
    Replies:
    0
    Views:
    496
    John Wallace
    Jul 22, 2003
  2. Matt
    Replies:
    3
    Views:
    550
    Tor Iver Wilhelmsen
    Sep 17, 2004
  3. Praveen Chhangani

    Converting a org.jdom DOC to org.w3c DOC

    Praveen Chhangani, Aug 5, 2003, in forum: XML
    Replies:
    2
    Views:
    1,021
    Johannes Koch
    Aug 7, 2003
  4. News123
    Replies:
    0
    Views:
    310
    News123
    Feb 6, 2010
  5. ~greg
    Replies:
    5
    Views:
    114
    John Bokma
    Feb 6, 2006
Loading...

Share This Page