Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


xerces-c schema validation

From: Harald Haspl <harald.haspl@----.--.-->
To: NULL
Date: 9/1/2005 1:52:00 PM
Hello,

I've appended a simple XML file and it's appropriate schema below.
I want to validate the XML file against the schema with xerces-c.

This example contains a section where colours are defined and a section
where referenzes to these definitions are made.
Values are valid only if they were defined above.

A key constraint is defined for Definition/Color/ids, keyref to
Data/Item/color.

If I use an undefined color value, the parser gives me this error message:
Error at file data.xml, line 18, char 12
"The key for identity constraint of element 'DemoFile' is not found."

This is not very helpful to find the actual errornous line, because this
line number is at the end of the file.

Is there a way to get more accurate information about which line is wrong?
Or is it impossible due to the way xerces deals with key and keyref
constraints (only in the scope of the element)?

best regards,
Harald.

---------8<--------- data.xml -------------------

<?xml version="1.0"?>
<DemoFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
    <Definition>
        <Color id="red"/>
        <Color id="green"/>
        <Color id="blue"/>
    </Definition>

    <Data>
        <Item color="red"></Item>
        <Item color="green"></Item>
        <Item color="blue"></Item>
        <Item color="green"></Item>
        <Item color="red"></Item>
    </Data>

</DemoFile>

---------8<-------end of data.xml ---------------


---------8<--------- schema.xsd -----------------


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="DemoFile">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Definition">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Color" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:attribute name="id" type="xs:string"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <xs:element name="Data">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Item" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:attribute name="color" type="xs:string"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>


    <xs:key name="TypeId">
      <xs:selector xpath="Definition/Color"/>
      <xs:field xpath="@id"/>
    </xs:key>
    <xs:keyref name="IdExists" refer="TypeId">
      <xs:selector xpath="Data/Item"/>
      <xs:field xpath="@color"/>
    </xs:keyref>
  </xs:element>
</xs:schema>


---------8<-------end of schema.xsd ---------------




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent