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


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


correct/test.xml:2: element sample: Schemas validity error : Element
'{}sample', attribute 'abc': The attribute 'abc' is
not allowed.
correct/test.xml:2: element sample: Schemas validity error : Element
'{}sample': The attribute
'{}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 '{}abc' 
is required but missing."
Thus, an attribute "abc" in the namespace ""; is
defined to be required, but is missing.

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="";
targetNamespace=""; elementFormDefault="qualified"
xmlns ="";>

<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 "";.

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<sample xmlns="";
xmlns:xsi=""; abc="23">

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

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

... - 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="";
 xmlns:xsi=""; test:abc="23">



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