Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0, confusingcvc-complex-type errors)

Discussion in 'XML' started by Grand Apeiron, Jan 18, 2004.

  1. Hi all,

    i am relatively new to XML and have created my own XML-Schema definition
    and an instance XML-Document out of it.
    I am working with netbeans-3.51 and the apache xerces XML Parser version
    2.6.0.
    When i validate the XML-Schema i get no errors.
    But when i validate the XML Instance i get errors about missing
    attributes and elements which seem to be correctly implemented from
    my sight of view.
    Please see the validation output and the XML Instance code
    to understand what i mean:
    ---<XML Instance Code

    <TBWPacket xmlns='TBWPacket'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='TBWPacket TBWPacket.xsd'
    >


    <packet-id>ABC00067</packet-id>
    <StandardPacket packet-length="12" packet-type="REQUEST">
    <md5sum>0</md5sum>
    <resp-for>TRCF0012</resp-for>
    <data>
    <string field-name='test'>send directory listing</string>
    </data>
    </StandardPacket>

    </TBWPacket>

    --->XML Instance Code

    ---<XML Validation output

    Checking
    file:/home/ob/programming/java/projects/TarByWire/TarByWire/Protocol/TBWStandardPacketExample.xml...
    Referenced entity at
    "file:/home/ob/programming/java/projects/TarByWire/TarByWire/Protocol/TBWPacket.xsd".
    cvc-complex-type.3.2.2: Attribute 'packet-length' is not allowed to
    appear in element 'StandardPacket'. [17]
    cvc-complex-type.3.2.2: Attribute 'packet-type' is not allowed to appear
    in element 'StandardPacket'. [17]
    cvc-complex-type.4: Attribute 'packet-length' must appear on element
    'StandardPacket'. [17]
    cvc-complex-type.4: Attribute 'packet-type' must appear on element
    'StandardPacket'. [17]
    cvc-complex-type.2.4.a: Invalid content was found starting with element
    'resp-for'. One of '{"":resp-for}' is expected. [19]
    cvc-complex-type.3.2.2: Attribute 'field-name' is not allowed to appear
    in element 'string'. [21]
    cvc-complex-type.4: Attribute 'field-name' must appear on element
    'string'. [21]
    XML validation finished.

    --->XML Validation output


    I really have no idea what could cause that problems. I dont even
    know if the problem lays in the XML-Schema or the XML-Instance.
    I will not include the schema definition here until someone requests it
    since it is around 250 lines long.

    If anybody has an idea what could cause the shown problem(s) that idea
    is highly requested =).


    Thanx for any help.
    With greetings from germany,
    Grand Apeiron
    Grand Apeiron, Jan 18, 2004
    #1
    1. Advertising

  2. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Grand Apeiron wrote:

    > i am relatively new to XML and have created my own XML-Schema definition
    > and an instance XML-Document out of it.
    > I am working with netbeans-3.51 and the apache xerces XML Parser version
    > 2.6.0.
    > When i validate the XML-Schema i get no errors.
    > But when i validate the XML Instance i get errors about missing
    > attributes and elements which seem to be correctly implemented from
    > my sight of view.
    > Please see the validation output and the XML Instance code
    > to understand what i mean:
    > ---<XML Instance Code
    >
    > <TBWPacket xmlns='TBWPacket'
    > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    > xsi:schemaLocation='TBWPacket TBWPacket.xsd'
    > >

    >
    > <packet-id>ABC00067</packet-id>
    > <StandardPacket packet-length="12" packet-type="REQUEST">
    > <md5sum>0</md5sum>
    > <resp-for>TRCF0012</resp-for>
    > <data>
    > <string field-name='test'>send directory listing</string>
    > </data>
    > </StandardPacket>
    >
    > </TBWPacket>


    > I really have no idea what could cause that problems. I dont even
    > know if the problem lays in the XML-Schema or the XML-Instance.
    > I will not include the schema definition here until someone requests it
    > since it is around 250 lines long.


    Please upload the XML file and the XML schema file to a public HTTP
    server and post the URLs, then we can check what might be wrong.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 18, 2004
    #2
    1. Advertising

  3. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Martin Honnen wrote:
    > Please upload the XML file and the XML schema file to a public HTTP
    > server and post the URLs, then we can check what might be wrong.
    >


    Hi Martin,

    thank you for your prompt answer.
    I uploaded the schema and the implementation to the following url's.
    http://www.euro-solutions.de/TBWPacket.xsd
    http://www.euro-solutions.de/TBWStandardPacketExample.xml.txt

    I also implemented a root element now, since that seems like good style
    to me.

    In addition i found out the following:
    I have a xsd:simpleType defintion and an attribute
    definition that uses that type.
    If i reference that defined attribute later from within an
    xsd:complexType i get the described error.
    But if i define a new attribute by giving it a name
    and the defined simpleType it works.
    So it seems like the error occurs only when referencing former
    defined types.
    But i am still not knowing whats really wrong.

    I have included the working attribute definition
    within the schema but commented it out.
    To find it search for "That would work".

    Thanks again for your help.

    With greetings,
    Grand Apeiron.
    Grand Apeiron, Jan 18, 2004
    #3
  4. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Grand Apeiron wrote:

    > Martin Honnen wrote:
    >
    >> Please upload the XML file and the XML schema file to a public HTTP
    >> server and post the URLs, then we can check what might be wrong.
    >>



    > I uploaded the schema and the implementation to the following url's.
    > http://www.euro-solutions.de/TBWPacket.xsd
    > http://www.euro-solutions.de/TBWStandardPacketExample.xml.txt


    It is getting too late to look into that in detail but having
    targetNamespace set for the schema but using
    elementFormDefault="unqualified"
    seems a very odd way, I suggest you use
    elementFormDefault="qualified"

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 18, 2004
    #4
  5. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Grand Apeiron wrote:

    > Martin Honnen wrote:
    >
    >> Please upload the XML file and the XML schema file to a public HTTP
    >> server and post the URLs, then we can check what might be wrong.
    >>


    > I uploaded the schema and the implementation to the following url's.
    > http://www.euro-solutions.de/TBWPacket.xsd
    > http://www.euro-solutions.de/TBWStandardPacketExample.xml.txt


    As far as I see it if you declare a global attribute (meaning you have
    <xs:attribute .../> as a child of <xs:schema>) then that attribute is
    always in the targetNamespace of the schema (if it has one and yours has
    one).
    Thus unless you want your attributes to be used as
    prefix:attributename="value"
    where prefix is bound to your target namespace you shouldn't use global
    attribute declarations.

    What should be possible is declaring a global attributeGroup with your
    attributes as needed and referencing that attributeGroup in the type of
    your element, there you should be able to have unqualified attributes if
    the <xs:schema attributeFormDefault="unqualified" ...> says so.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 19, 2004
    #5
  6. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Martin Honnen wrote:
    > As far as I see it if you declare a global attribute (meaning you have
    > <xs:attribute .../> as a child of <xs:schema>) then that attribute is
    > always in the targetNamespace of the schema (if it has one and yours has
    > one).
    > Thus unless you want your attributes to be used as
    > prefix:attributename="value"
    > where prefix is bound to your target namespace you shouldn't use global
    > attribute declarations.
    >
    > What should be possible is declaring a global attributeGroup with your
    > attributes as needed and referencing that attributeGroup in the type of
    > your element, there you should be able to have unqualified attributes if
    > the <xs:schema attributeFormDefault="unqualified" ...> says so.
    >


    OK. Thanks.
    So what i understand is that i should not use global attribute declarations.
    But what is a good way then to declare attributes only once and
    reuse them everywhere when needed.
    How do others do that? Or is now one doing that at all?
    If i bring the problem down to an OO approach i have some objects
    which are special in their own way but sharing the same attribute which
    i only want to declare once.
    Isn't there a standard way in XML-(Schema) to do so?

    Thanks for your help.
    Greetz,
    Grand Apeiron
    Grand Apeiron, Jan 19, 2004
    #6
  7. Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Grand Apeiron wrote:

    > Martin Honnen wrote:
    >
    >> As far as I see it if you declare a global attribute (meaning you have
    >> <xs:attribute .../> as a child of <xs:schema>) then that attribute is
    >> always in the targetNamespace of the schema (if it has one and yours
    >> has one).
    >> Thus unless you want your attributes to be used as
    >> prefix:attributename="value"
    >> where prefix is bound to your target namespace you shouldn't use
    >> global attribute declarations.
    >>
    >> What should be possible is declaring a global attributeGroup with your
    >> attributes as needed and referencing that attributeGroup in the type
    >> of your element, there you should be able to have unqualified
    >> attributes if the <xs:schema attributeFormDefault="unqualified" ...>
    >> says so.
    >>



    > So what i understand is that i should not use global attribute
    > declarations.


    You can use them, but if your schema has a target namespace then a
    global attribute is a qualified one so any use of it needs to be as
    <element xmlns:prefix="targetnamespacegoeshere"
    prefix:attributename="value">
    At least that is my current understanding. Anyone else reading here and
    dissenting?

    > But what is a good way then to declare attributes only once and
    > reuse them everywhere when needed.
    > How do others do that? Or is now one doing that at all?
    > If i bring the problem down to an OO approach i have some objects
    > which are special in their own way but sharing the same attribute which
    > i only want to declare once.
    > Isn't there a standard way in XML-(Schema) to do so?


    As suggested above one way is to use an attributeGroup, here is an
    example, the XML instance is

    <gods xmlns="http://vatican.va/gods/2004/01"
    xmlns:va="http://vatican.va/gods/2004/01"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://vatican.va/gods/2004/01
    test20040119Xsd.xml">
    <god name="Kibo" home="http://www.kibo.com" />
    <devil name="Xibo" />
    </gods>

    the XML schema

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://vatican.va/gods/2004/01"
    xmlns:va="http://vatican.va/gods/2004/01"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:attributeGroup name="standard">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="home" type="xs:string" />
    </xs:attributeGroup>

    <xs:element name="gods">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="god">
    <xs:complexType>
    <xs:attributeGroup ref="va:standard" />
    </xs:complexType>
    </xs:element>
    <xs:element name="devil">
    <xs:complexType>
    <xs:attributeGroup ref="va:standard" />
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>

    </xs:schema>
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 19, 2004
    #7
  8. Grand Apeiron

    Peter Flynn Guest

    Re: Newbie problem?: XML-Schema Instance Validation (xerces 2.6.0,confusing cvc-complex-type errors)

    Grand Apeiron wrote:
    > Hi all,
    >
    > i am relatively new to XML and have created my own XML-Schema definition
    > and an instance XML-Document out of it.
    > I am working with netbeans-3.51 and the apache xerces XML Parser version
    > 2.6.0.
    > When i validate the XML-Schema i get no errors.
    > But when i validate the XML Instance i get errors about missing
    > attributes and elements which seem to be correctly implemented from
    > my sight of view.


    *Always* test out these things in a validating XML editor, rather than
    trying to test them at second hand via an API or at third hand inside
    a program of your own.

    ///Peter
    Peter Flynn, Jan 20, 2004
    #8
    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,497
    Markus
    Nov 23, 2005
  2. Mike
    Replies:
    1
    Views:
    1,142
    Patrick TJ McPhee
    Nov 21, 2003
  3. Olaf Meyer
    Replies:
    2
    Views:
    675
    Olaf Meyer
    Jan 15, 2004
  4. Stanimir Stamenkov
    Replies:
    2
    Views:
    734
    Stanimir Stamenkov
    Oct 25, 2005
  5. Replies:
    5
    Views:
    980
    Brian McCauley
    Nov 29, 2006
Loading...

Share This Page