[Mono-bugs] [Bug 501763] New: Xml schema validation fails when using xs:import (patch included)
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu May 7 09:29:00 EDT 2009
http://bugzilla.novell.com/show_bug.cgi?id=501763
Summary: Xml schema validation fails when using xs:import
(patch included)
Classification: Mono
Product: Mono: Class Libraries
Version: 2.4.x
Platform: i686
OS/Version: Ubuntu
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Sys.XML
AssignedTo: atsushi at ximian.com
ReportedBy: jonas.larsson at manodo.se
QAContact: mono-bugs at lists.ximian.com
Found By: ---
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10)
Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10
Please run the following test case:
string xsd1 = @"
<xs:schema id='foo1'
targetNamespace='foo1'
elementFormDefault='qualified'
xmlns='foo1'
xmlns:xs='http://www.w3.org/2001/XMLSchema'
xmlns:f2='foo2'>
<xs:import namespace='foo2' />
<xs:element name='Foo1Element' type='f2:Foo2ExtendedType'/>
</xs:schema>";
string xsd2 = @"
<xs:schema id='foo2'
targetNamespace='foo2'
elementFormDefault='qualified'
xmlns='foo2'
xmlns:xs='http://www.w3.org/2001/XMLSchema' >
<xs:element name='Foo2Element' type='Foo2Type' />
<xs:complexType name='Foo2Type'>
<xs:attribute name='foo2Attr' type='xs:string' use='required'/>
</xs:complexType>
<xs:complexType name='Foo2ExtendedType'>
<xs:complexContent>
<xs:extension base='Foo2Type'>
<xs:attribute name='foo2ExtAttr' type='xs:string' use='required'/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>";
XmlDocument doc = new XmlDocument ();
XmlSchema schema1 = XmlSchema.Read (XmlReader.Create (new StringReader (xsd1)),
null);
XmlSchema schema2 = XmlSchema.Read (XmlReader.Create (new StringReader (xsd2)),
null);
doc.LoadXml (@"
<Foo2Element
foo2Attr='dummyvalue1'
xmlns='foo2'
/>");
doc.Schemas.Add (schema2);
doc.Validate (null);
doc = new XmlDocument();
doc.LoadXml(@"
<Foo1Element
foo2Attr='dummyvalue1'
foo2ExtAttr='dummyvalue2'
xmlns='foo1'
/>");
doc.Schemas.Add (schema2);
doc.Schemas.Add (schema1);
doc.Validate (null);
---------
Running this on mono gives:
System.Xml.Schema.XmlSchemaException: XmlSchema error: Named item foo2Attr was
already contained in the schema object table. Related schema item SourceUri: ,
Line 11, Position 7.
---------
Cause:
When validating second document schema2's types are already compiled and
validated. However, checking IsCompiled the second time returns false since we
have a new validationId on the schema. The result is that schema2's types are
compiled again. On a XmlSchemaComplexType the attributeUses collection then
already contains the results from the previous validation. When validated
again, the above Exception is thrown.
Solution:
Clear XmlSchemaComplexType.attributeUses before Compilation. The patch is a one
liner. Add
attributeUses.Clear()
in the beginning of XmlSchemaComplexType.Compile.
Will upload diff once I've submitted this and gotten a bug number.
Reproducible: Always
Steps to Reproduce:
Run above code
Actual Results:
Exception
Expected Results:
Successful validation
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list