AW: [xml] libxml schema validation - conflict result on attributevalidation



Hi, 

-----Ursprüngliche Nachricht-----
Von: xml-bounces gnome org [mailto:xml-bounces gnome org] Im 

I'm trying libxml on a very simple same file and got some rather
conflicting result. I'm still learning schema and libxml so any tip is
much appreciated.

Thanks.

result:
correct/test.xml:2: element sample: Schemas validity error : Element
'{http://www.test.com}sample', attribute 'abc': The attribute 'abc' is
not allowed.
correct/test.xml:2: element sample: Schemas validity error : Element
'{http://www.test.com}sample': The attribute
'{http://www.test.com}abc' is required but missing.
correct/test.xml fails to validate

This looks like a conflict at first glance, but it isn't.

The first error reports: "The attribute 'abc' is not allowed."
Thus, an attribute "abc" in *no* namespace in not allowed.

The second error reports: "The attribute '{http://www.test.com}abc' 
is required but missing."
Thus, an attribute "abc" in the namespace "http://www.test.com"; is
defined to be required, but is missing.

xsd:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.test.com"; elementFormDefault="qualified"
xmlns ="http://www.test.com";>

<xs:attribute name="abc" type="xs:integer"/>

This is a global attribute declaration. Global element/attribute
declarations declare the element/attribute to be in the
*targetNamespace". So you declare the attribute "abc" to be
in the namespace "http://www.text.com";.

<xs:element name="sample">
    <xs:complexType>
        <xs:sequence>
                <xs:element name="test"/>
        </xs:sequence>
        <xs:attribute ref="abc" use="required"/>
    </xs:complexType>
</xs:element>
</xs:schema>


xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<sample xmlns="http://www.test.com";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; abc="23">
<test/>
</sample>

The attribute "abc" in this instance document is in *no* namespace;
thus not the one you actually declared in the schema.

I hope this clarifies the error reports.

To fix your scenario, either you declare a *local* attribute in
the schema (you also may want to read about the implications of
"attributeFormDefault"):

<xs:complexType>
  ...
  <xs:attribute name="abc" use="required"/>
</xs:complexType>

... - this way the attribute "abc" will be in no namespace -,
or you fix your instance document by putting the attribute
"abc" into the declared namespace:

<test:sample xmlns:test="http://www.test.com";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; test:abc="23">


Regards,

Kasimier




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]