[lxml-dev] Question about schema validation
Hi all I am using both lxml (version 2.2.2) and XmlCopyEditor (XCE) to validate some instance documents against a schema. I have come across a situation where XCE reports an error, but lxml does not. AFAICT XCE is correct. Could this be a bug in lxml? Here is a snippet from the instance document - <resource id="regionalManager" name="Regional Manager"> <resourceParameter id="buyerName" isRequired="true" name="Buyer Name" type="xs:string"/> <resourceParameter id="region" isRequired="false" name="Region" type="xs:string"/> </resource> <resource id="departmentalReviewer" name="Departmental Reviewer"> <resourceParameter id="buyerName" isRequired="true" name="Buyer Name" type="xs:string"/> </resource> Here is the relevant section from the schema - <xsd:element name="resourceParameter" type="tResourceParameter"/> <xsd:complexType name="tResourceParameter"> <xsd:complexContent> <xsd:extension base="tBaseElement"> <xsd:attribute name="name" type="xsd:string"/> <xsd:attribute name="type" type="xsd:QName"/> <xsd:attribute name="isRequired" type="xsd:boolean"/> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:element name="baseElement" type="tBaseElement"/> <xsd:complexType name="tBaseElement" abstract="true"> <xsd:sequence> <xsd:element ref="documentation" minOccurs="0" maxOccurs="unbounded"/> <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:ID" use="optional"/> <xsd:anyAttribute namespace="##other" processContents="lax"/> </xsd:complexType> The error message reported by XCE is 'ID buyerName is not unique'. Any thoughts? Frank Millman
Frank Millman wrote:
I have come across a situation where XCE reports an error, but lxml does not. AFAICT XCE is correct. Could this be a bug in lxml? [...] The error message reported by XCE is 'ID buyerName is not unique'.
XML Schema support is known to have minor issues in libxml2. Please make sure you use the latest version of libxml2. Then try to validate the document using xmllint (a tool that comes with libxml2), and if that fails (well, or fails to fail in this case), report the problem on the libxml2 mailing list. Stefan
Stefan Behnel wrote:
Frank Millman wrote:
I have come across a situation where XCE reports an error, but lxml does not. AFAICT XCE is correct. Could this be a bug in lxml? [...] The error message reported by XCE is 'ID buyerName is not unique'.
XML Schema support is known to have minor issues in libxml2. Please make sure you use the latest version of libxml2. Then try to validate the document using xmllint (a tool that comes with libxml2), and if that fails (well, or fails to fail in this case), report the problem on the libxml2 mailing list.
It is fixed in libxml2 2.7.4. <aside> The error message is not as clear as XCE. It says: 'buyerName' is not a valid value of the atomic type 'xs:ID'. But at least the validation fails, which is the important thing. </aside> Thanks, Stefan. Frank
Hi,
Stefan Behnel wrote:
Frank Millman wrote:
I have come across a situation where XCE reports an error, but lxml does not. AFAICT XCE is correct. Could this be a bug in lxml? [...] The error message reported by XCE is 'ID buyerName is not unique'.
XML Schema support is known to have minor issues in libxml2. Please make sure you use the latest version of libxml2. Then try to validate the document using xmllint (a tool that comes with libxml2), and if that fails (well, or fails to fail in this case), report the problem on the libxml2 mailing list.
It is fixed in libxml2 2.7.4.
<aside> The error message is not as clear as XCE. It says: 'buyerName' is not a valid value of the atomic type 'xs:ID'. But at least the validation fails, which is the important thing. </aside>
FWIW, oxygen (Xerces) reports both errors: E [Xerces] cvc-attribute.3: The value 'buyerName' of attribute 'id' on element 'resourceParameter' is not valid with respect to its type, 'ID'. E [Xerces] cvc-id.2: There are multiple occurrences of ID value 'buyerName'. The XMLSchema coverage got me curious. Here's bits I found out: A statement on the libxml2 mailing list wrt XMLSchema support: http://www.mail-archive.com/xml@gnome.org/msg06791.html W3C offers some schema test suite consisting of schemas, instance docs, and expected validation results, although the info is a bit scattered (I'm not even sure which is the latest "official" version of the tests). With a little test harness that I whipped up I get these results (for the test suite found here: http://www.w3.org/XML/2004/xml-schema-test-suite/xmlschema2006-11-06/xsts-20...) *** Running test suite suite.xml *** Ran 39420 tests, 37473 ok, 0 failed, 1718 non-canonical failed (canonical test states: ['stable']) Non-canonical failures: {'queried': 54, 'accepted': 1664} 229 tests could not be run: {'schema ../msData/particles/particlesZ015.xsd manually excluded': 1, 'schema ../msData/datatypes/datatypes.xsd manually excluded': 1, 'schema ../msData/particles/particlesZ012.xsd manually excluded': 1, 'XMLSyntaxError': 3, 'XMLSchemaParseError': 221, 'schema ../msData/additional/test264908_1.xsd manually excluded': 2} No guarantees that these are sensible results... Some tests I cannot run due to segfaults when instantiating etree.XMLSchema so I manually exclude them. So either: - the test for ID uniqueness is not in "stable" state - there is no test for it - it's buried in schemas that I have to exclude - my test harness is horribly broken ;-) I'm running lxml 2.2.2 with libxml2 (2, 6, 32) and libxslt (1, 1, 23) on solaris. Holger -- Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
On Thu, 2009-09-17 at 10:05 +0200, Frank Millman wrote:
<resource id="regionalManager" name="Regional Manager"> <resourceParameter id="buyerName" .../>
...
</resource>
<resource id="departmentalReviewer" name="Departmental Reviewer"> <resourceParameter id="buyerName" .../> </resource>
Here is the relevant section from the schema -
<xsd:attribute name="id" type="xsd:ID" use="optional"/>
The error message reported by XCE is 'ID buyerName is not unique'.
Any thoughts?
Sounds correct for me. The schema type xsd:ID defines a unique identifier inside the whole document. If there are obviously two IDs with the same value, this is an error. If dont want the scope of the ID to be over the whole file, you would need to use xsd:key or xsd:unique inside the schema. regards Daniel
participants (4)
-
Daniel Albeseder
-
Frank Millman
-
jholg@gmx.de
-
Stefan Behnel