[libxml2] XSD: optional element in complex type extension



commit 4609e6c980b256e4115d4b7e1227f59870465995
Author: Remi Gacogne <rgacogne-xml coredump fr>
Date:   Fri May 11 15:31:05 2012 +0800

    XSD: optional element in complex type extension
    
    For https://bugzilla.gnome.org/show_bug.cgi?id=609796
    Libxml2 fails to validate an instance document against a schema if an element
    whose type is a complex extension of some base type with an optional child
    element and that child element is not specified in the instance document.  For
    example, suppose I have some complex type BaseType that is defined to have one
    child element in a sequence group that has minOccurs set to 0

 result/schemas/complex-type-extension_0_0     |    1 +
 test/schemas/complex-type-extension_0.xml     |   12 +++++++++++
 test/schemas/complex-type-extension_0.xsd     |   27 +++++++++++++++++++++++++
 xmlschemas.c                                  |    4 +-
 4 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/result/schemas/complex-type-extension_0_0 b/result/schemas/complex-type-extension_0_0
new file mode 100644
index 0000000..ef15215
--- /dev/null
+++ b/result/schemas/complex-type-extension_0_0
@@ -0,0 +1 @@
+./test/schemas/complex-type-extension_0.xml validates
diff --git a/result/schemas/complex-type-extension_0_0.err b/result/schemas/complex-type-extension_0_0.err
new file mode 100644
index 0000000..e69de29
diff --git a/test/schemas/complex-type-extension_0.xml b/test/schemas/complex-type-extension_0.xml
new file mode 100644
index 0000000..8cdda23
--- /dev/null
+++ b/test/schemas/complex-type-extension_0.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ItemsList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+ <Item xsi:type="ItemWithNumber">
+  <Name>Name1</Name>
+  <Number>20</Number>
+ </Item>
+ <Item xsi:type="ItemWithNumber">
+  <Name>Name1</Name>
+  <Name>Name2</Name>
+  <Number>20</Number>
+ </Item>
+</ItemsList>
diff --git a/test/schemas/complex-type-extension_0.xsd b/test/schemas/complex-type-extension_0.xsd
new file mode 100644
index 0000000..6a6237a
--- /dev/null
+++ b/test/schemas/complex-type-extension_0.xsd
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+
+ <xs:complexType name="Item" abstract="true">
+  <xs:sequence minOccurs="1" maxOccurs="unbounded">
+    <xs:element name="Name" type="xs:string"/>
+  </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="ItemWithNumber">
+  <xs:complexContent>
+   <xs:extension base="Item">
+    <xs:sequence>
+     <xs:element name="Number" type="xs:nonNegativeInteger"/>
+    </xs:sequence>
+   </xs:extension>
+  </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="ItemsList">
+  <xs:complexType>
+   <xs:sequence>
+    <xs:element name="Item" type="Item" maxOccurs="unbounded"/>
+   </xs:sequence>
+  </xs:complexType>
+ </xs:element>
+</xs:schema>
diff --git a/xmlschemas.c b/xmlschemas.c
index 5a5b41e..2fb2151 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -18476,8 +18476,8 @@ xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
 		    particle->children->children =
 			(xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt,
 			type->node,
-			((xmlSchemaParticlePtr) type->subtypes)->minOccurs,
-			((xmlSchemaParticlePtr) type->subtypes)->maxOccurs);
+			((xmlSchemaParticlePtr) baseType->subtypes)->minOccurs,
+			((xmlSchemaParticlePtr) baseType->subtypes)->maxOccurs);
 		    if (particle->children->children == NULL)
 			goto exit_failure;
 		    particle = (xmlSchemaParticlePtr)



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