Schema with ID/IDREF validates, but xml-file that uses it does not

Discussion in 'XML' started by Eric Lilja, Feb 21, 2007.

  1. Eric Lilja

    Eric Lilja Guest

    Sorry for asking so many questions, but I've just started and need to
    get some things working so I can do the task that is before me.

    Consider this (validating) schema:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="myns" xmlns="myns" elementFormDefault="qualified">
    <xs:element name="books">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="book" minOccurs="0"
    maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="author" minOccurs="1"
    maxOccurs="1">
    <xs:complexType>
    <xs:attribute name="id" type="xs:ID"
    use="required"/>
    <xs:attribute name="name" type="xs:string"
    use="required"/>
    </xs:complexType> <!-- authors complexType -->
    </xs:element> <!-- author -->
    </xs:sequence> <!-- book sequence -->
    <xs:attribute name="title" type="xs:string"
    use="required"/>
    <xs:attribute name="isbn" type="xs:string"
    use="required"/>
    <xs:attribute name="author-id" type="xs:IDREF"
    use="required"/>
    </xs:complexType> <!-- book complexType -->
    </xs:element> <!-- book -->
    </xs:sequence> <!-- books sequence -->
    </xs:complexType> <!-- books complexType -->
    </xs:element> <!-- books -->
    </xs:schema>

    I try to use it with the following xml-file:
    <?xml version="1.0" encoding="utf-8"?>
    <books xmlns="myns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
    instance" xsi:schemaLocation="myns books-with-id_idref.xsd">
    <book title="Winter's Heart" isbn="123456789" author-id="4711">
    <author id="4711" name="Robert Jordan"/>
    </book>
    <book title="Paradiset" isbn="987654321" author-id="1337">
    <author id="1337" name="Liza Marklund"/>
    </book>
    </books>

    But I get these errors:
    Location: 3:66
    Description: cvc-datatype-valid.1.2.1: '4711' is not a valid value for
    'NCName'.

    Location: 3:59
    Description: cvc-attribute.3: The value '4711' of attribute 'author-
    id' on element 'book' is not valid with respect to its type, 'IDREF'.

    Location: 4:45
    Description: cvc-datatype-valid.1.2.1: '4711' is not a valid value for
    'NCName'.

    Location: 4:16
    Description: cvc-attribute.3: The value '4711' of attribute 'id' on
    element 'author' is not valid with respect to its type, 'ID'.

    Location: 6:61
    Description: cvc-datatype-valid.1.2.1: '1337' is not a valid value for
    'NCName'.

    Location: 6:54
    Description: cvc-attribute.3: The value '1337' of attribute 'author-
    id' on element 'book' is not valid with respect to its type, 'IDREF'.

    Location: 7:45
    Description: cvc-datatype-valid.1.2.1: '1337' is not a valid value for
    'NCName'.

    Location: 7:16
    Description: cvc-attribute.3: The value '1337' of attribute 'id' on
    element 'author' is not valid with respect to its type, 'ID'.

    I've clearly not understood this..what am I doing wrong and what need
    I do to get it working?

    Thanks for any replies! :)

    - Eric
    Eric Lilja, Feb 21, 2007
    #1
    1. Advertising

  2. Eric Lilja

    roy axenov Guest

    On Feb 21, 8:22 pm, "Eric Lilja" <>
    wrote:
    > Sorry for asking so many questions, but I've just started
    > and need to get some things working so I can do the task
    > that is before me.


    Read a book. You're not going to learn much if you just ask
    lots of questions and make no effort to learn on your own.

    http://www.w3.org/TR/xmlschema-0/

    ....is a good enough starting point for learning about XML
    Schemata.

    > Location: 3:66
    > Description: cvc-datatype-valid.1.2.1: '4711' is not a
    > valid value for 'NCName'.


    It tells you precisely what is wrong with your document.
    You declared this attribute as xs:IDREF. '4711' is not a
    valid xs:IDREF value. Finding out why should be trivial
    for anyone with intelligence quotient higher than their
    shoe size.

    XML Schema Recommendations are published by W3C. On their
    website you should see an XML Schema section in the list of
    available topics. Click there.

    You need Specifications and Development sub-sections. Click
    on it.

    'XML Schema Part 2: Datatypes' looks like it might help
    you. Click it.

    Search for IDREF. Click on the link. The text says that
    IDREF is the set of all string that match the NCName
    production. Click on NCName.

    [4] NCName ::= (Letter | '_') (NCNameChar)*

    Here it goes... looks like IDREF's (and ID's) have to start
    with a letter or an underscore. That's your immediate
    problem, and the error message you received together with
    good ole rubbing a couple of brain cells together should've
    gotten you there in two minutes or so.

    > I've clearly not understood this..what am I doing wrong
    > and what need I do to get it working?


    I think it would be harmful for you to simply tell you how
    it's done. But I'll give you an awfully good hint: XML
    Schema Part 0: Primer document I referred above contains
    the information necessary for doing it right.

    --
    roy axenov
    roy axenov, Feb 21, 2007
    #2
    1. Advertising

  3. Eric Lilja

    Eric Lilja Guest

    On 21 Feb, 19:46, "roy axenov" <> wrote:
    > On Feb 21, 8:22 pm, "Eric Lilja" <>
    > wrote:
    >
    > > Sorry for asking so many questions, but I've just started
    > > and need to get some things working so I can do the task
    > > that is before me.

    >
    > Read a book. You're not going to learn much if you just ask
    > lots of questions and make no effort to learn on your own.


    I have the book Internet and the World Wide Web How to program, which,
    briefly, discusses xml. I'm starting out with several "technologies"
    related to web right now so that book seemed a good purchase. Since
    the book is a bit light on XML I've been using the web alongside. XML
    is one thing that I want to have more than a cursory knowledge of,
    though, so I'm trying to decide on a good book. I was looking at
    O'Reilly's selection and plan to visit the local campus library to do
    some browsing and see which one I like. One of my upcoming projects is
    changing my applications to use xml for storing user settings and
    whatnot.

    >
    > http://www.w3.org/TR/xmlschema-0/
    >
    > ...is a good enough starting point for learning about XML
    > Schemata.


    This link keeps turning up when I google but, unfortunately, the
    information is somewhat densely presented for me at the moment.

    >
    > > Location: 3:66
    > > Description: cvc-datatype-valid.1.2.1: '4711' is not a
    > > valid value for 'NCName'.

    >
    > It tells you precisely what is wrong with your document.
    > You declared this attribute as xs:IDREF. '4711' is not a
    > valid xs:IDREF value. Finding out why should be trivial
    > for anyone with intelligence quotient higher than their
    > shoe size.
    >
    > XML Schema Recommendations are published by W3C. On their
    > website you should see an XML Schema section in the list of
    > available topics. Click there.
    >
    > You need Specifications and Development sub-sections. Click
    > on it.
    >
    > 'XML Schema Part 2: Datatypes' looks like it might help
    > you. Click it.
    >
    > Search for IDREF. Click on the link. The text says that
    > IDREF is the set of all string that match the NCName
    > production. Click on NCName.
    >
    > [4] NCName ::= (Letter | '_') (NCNameChar)*
    >
    > Here it goes... looks like IDREF's (and ID's) have to start
    > with a letter or an underscore. That's your immediate
    > problem, and the error message you received together with
    > good ole rubbing a couple of brain cells together should've
    > gotten you there in two minutes or so.
    >
    > > I've clearly not understood this..what am I doing wrong
    > > and what need I do to get it working?

    >
    > I think it would be harmful for you to simply tell you how
    > it's done. But I'll give you an awfully good hint: XML
    > Schema Part 0: Primer document I referred above contains
    > the information necessary for doing it right.


    A bit rudely put I think, but I guess that's easy on the internet. I
    did search for it, though, but I didn't look closely enough and was
    confused by an example that used integer literals as IDs. But, you're
    right, I should have been able to find the proper definition myself.
    Anyway, you solved my problem and for that I say thanks.

    >
    > --
    > roy axenov


    - Eric
    Eric Lilja, Feb 21, 2007
    #3
  4. Re: Schema with ID/IDREF validates, but xml-file that uses it doesnot

    Reading W3C documents, even introductory ones, does assume a basic level
    of experience which beginners may not have. They're written by experts,
    for experts, so they tend to be terse; the official goal seems to be to
    make them "prescriptive, not descriptive", and I actually got some
    pushback when folks felt I was crossing that line. The assumption seems
    to be that other people will take the W3C books and write tutorial
    material based on them.

    And, in fact, there are also many tutorials and introductory articles
    available on the web.

    I hope folks will forgive me for blowing the company trumpet again and
    reminding everyone that many of those resources can be found at
    http://www.ibm.com/xml
    And in other places, of course.
    Joseph Kesselman, Feb 21, 2007
    #4
    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. Markus
    Replies:
    1
    Views:
    1,530
    Markus
    Nov 23, 2005
  2. Titus A Ducksass - AKA broken-record
    Replies:
    6
    Views:
    651
    Titus A Ducksass - AKA broken-record
    Nov 15, 2004
  3. Radu
    Replies:
    8
    Views:
    416
  4. dorayme
    Replies:
    2
    Views:
    404
    dorayme
    Nov 7, 2010
  5. 123Jim
    Replies:
    0
    Views:
    432
    123Jim
    Nov 6, 2010
Loading...

Share This Page