[xml] XML Schema: Nillable custom type error (PATCH)
- From: Sir Woody Hackswell <woody hackswell com>
- To: xml gnome org
- Subject: [xml] XML Schema: Nillable custom type error (PATCH)
- Date: Sat, 05 Nov 2005 20:23:17 -0500
Hello, all! I believe I've come across a problem with Schema validation.
Here's my scenario:
I have a custom type (in this example, "pricetype". My Element is
nillable, but the validator always bombs on it, because the "" item
isn't in my xs:pattern list. Nillable should hit before we check
patterns, no? Below my example is a small patch. Thank you.
-Richard Balint
woody @AT@ hackswell.DOT.com
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Book>
<Title>How to Write XML</Title>
<Author>Richard Balint</Author>
<Price></Price>
</Book>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Author" type="xs:string"/>
<xs:element name="Price" type="pricetype" nillable="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="pricetype">
<xs:restriction base="xs:string">
<xs:pattern value="$\d+\.\d\d"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Patch against libxml2-2.6.22:
--- xmlschemas.c.orig 2005-09-12 17:39:46.000000000 -0400
+++ xmlschemas.c 2005-11-05 20:16:04.000000000 -0500
@@ -21494,6 +21494,10 @@
ret = xmlRegexpExec(facetLink->facet->regexp, value);
if (ret == 1)
break;
+ else if ((type->flags & XML_SCHEMAS_ELEM_NILLABLE) && (*value
== '\0')) {
+ ret = 1;
+ break;
+ }
else if (ret < 0) {
AERROR_INT("xmlSchemaValidateFacets",
"validating against a pattern facet");
@@ -23100,11 +23104,16 @@
return (xmlSchemaVCheckCVCSimpleType(
ACTXT_CAST vctxt, NULL,
type, value, &(inode->val), 1, 1, 0));
- else
+ else {
+
+ if (inode->decl->flags & XML_SCHEMAS_ELEM_NILLABLE) {
+ type->flags |= XML_SCHEMAS_ELEM_NILLABLE;
+ }
return (xmlSchemaVCheckCVCSimpleType(
ACTXT_CAST vctxt, NULL,
type, value, NULL, 1, 0, 0));
}
+}
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]