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

G

Grand Apeiron

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
 
M

Martin Honnen

Grand said:
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.
 
G

Grand Apeiron

Martin said:
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.
 
M

Martin Honnen


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

Grand Apeiron

Martin said:
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
 
M

Martin Honnen

Grand said:
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>
 
P

Peter Flynn

Grand said:
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
 

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
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top