http://bugzilla.novell.com/show_bug.cgi?id=595947
http://bugzilla.novell.com/show_bug.cgi?id=595947#c0 Summary: XML Schema inheritance and validation bugs Classification: Mono Product: Mono: Class Libraries Version: 2.6.x Platform: All OS/Version: All Status: NEW Severity: Critical Priority: P5 - None Component: Sys.XML AssignedTo: atsu...@ximian.com ReportedBy: han.w...@morningstar.com QAContact: mono-bugs@lists.ximian.com Found By: Component Test Blocker: --- Created an attachment (id=353905) --> (http://bugzilla.novell.com/attachment.cgi?id=353905) Schema.xsd Description of Problem: The following sample code reproduces two bugs of schema validation 1. Attribute is not inherited (TEST 1.* and 2.*) 2. Facet of elements is not validated (TEST 3.*) I actually used some other similar methods to validate, but got the same result. I guess they use the same private method for validation. Explanation of the test results are in the end of this report. Please fix, thanks!!! Steps to reproduce the problem: Schema.xsd: ---------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:simpleType name="MyString"> <xs:restriction base="xs:string"> <xs:maxLength value="10" /> </xs:restriction> </xs:simpleType> <xs:complexType name="MyType"> <xs:simpleContent> <xs:extension base="MyString"> <xs:attribute name="Id" type="MyString" use="required" /> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:element name="MyTest1"> <xs:complexType> <xs:simpleContent> <xs:restriction base="MyType"> <xs:maxLength value="10" /> </xs:restriction> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="MyTest2"> <xs:complexType> <xs:simpleContent> <xs:restriction base="MyType"> <xs:attribute name="Id" type="MyString" use="required" /> </xs:restriction> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="MyTest3"> <xs:complexType> <xs:simpleContent> <xs:restriction base="MyType"> <xs:maxLength value="10" /> <xs:attribute name="Id" type="MyString" use="required" /> </xs:restriction> </xs:simpleContent> </xs:complexType> </xs:element> </xs:schema> ---------------------------------------------------- CS code: ---------------------------------------------------- using System; using System.IO; using System.Xml; using System.Xml.Schema; namespace SchemaValidationBugs { class Program { public static void Main(string[] args) { try { XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add(null,"Schema.xsd"); settings.ValidationType = ValidationType.Schema; settings.Schemas.Compile(); Validate("TEST 1.1",1,"0123456789","0123456789",settings); Validate("TEST 1.2",1,"0123456789***","0123456789",settings); Validate("TEST 1.3",1,"0123456789","0123456789***",settings); Validate("TEST 2.1",2,"0123456789","0123456789",settings); Validate("TEST 2.2",2,"0123456789***","0123456789",settings); Validate("TEST 2.3",2,"0123456789","0123456789***",settings); Validate("TEST 3.1",3,"0123456789","0123456789",settings); Validate("TEST 3.2",3,"0123456789***","0123456789",settings); Validate("TEST 3.3",3,"0123456789","0123456789***",settings); } catch(Exception e) { Console.WriteLine(e.ToString()); } } private static void Validate(string testName, int testNumber, string idValue, string elementValue, XmlReaderSettings settings) { string content=string.Format("<MyTest{0} Id=\"{1}\">{2}</MyTest{0}>",testNumber,idValue,elementValue); Console.WriteLine("---------- "+testName+" ----------"); Console.WriteLine("Validating: "+content); try { XmlReader reader = XmlReader.Create(new StringReader(content), settings); XmlDocument document = new XmlDocument(); document.Load(reader); document.Validate(null); Console.WriteLine("No error found"); } catch(Exception e) { Console.WriteLine("Validation failed: "+e.Message); } Console.WriteLine(""); } } } ---------------------------------------------------- Actual Results: ---------- TEST 1.1 ---------- Validating: <MyTest1 Id="0123456789">0123456789</MyTest1> Validation failed: XmlSchema error: Attribute declaration was not found for Id XML Line 1, Position 10. ---------- TEST 1.2 ---------- Validating: <MyTest1 Id="0123456789***">0123456789</MyTest1> Validation failed: XmlSchema error: Attribute declaration was not found for Id XML Line 1, Position 10. ---------- TEST 1.3 ---------- Validating: <MyTest1 Id="0123456789">0123456789***</MyTest1> Validation failed: XmlSchema error: Attribute declaration was not found for Id XML Line 1, Position 10. ---------- TEST 2.1 ---------- Validating: <MyTest2 Id="0123456789">0123456789</MyTest2> No error found ---------- TEST 2.2 ---------- Validating: <MyTest2 Id="0123456789***">0123456789</MyTest2> Validation failed: XmlSchema error: Specified value was invalid against the facets. XML Line 1, Position 10. ---------- TEST 2.3 ---------- Validating: <MyTest2 Id="0123456789">0123456789***</MyTest2> No error found ---------- TEST 3.1 ---------- Validating: <MyTest3 Id="0123456789">0123456789</MyTest3> No error found ---------- TEST 3.2 ---------- Validating: <MyTest3 Id="0123456789***">0123456789</MyTest3> Validation failed: XmlSchema error: Specified value was invalid against the facets. XML Line 1, Position 10. ---------- TEST 3.3 ---------- Validating: <MyTest3 Id="0123456789">0123456789***</MyTest3> No error found Expected Results: ---------- TEST 1.1 ---------- Validating: <MyTest1 Id="0123456789">0123456789</MyTest1> No error found ---------- TEST 1.2 ---------- Validating: <MyTest1 Id="0123456789***">0123456789</MyTest1> Validation failed: The 'Id' attribute is invalid - The value '0123456789***' is invalid according to its datatype 'MyString' - The actual length is greater than the MaxLength value. ---------- TEST 1.3 ---------- Validating: <MyTest1 Id="0123456789">0123456789***</MyTest1> Validation failed: The 'MyTest1' element is invalid - The value '0123456789***' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value. ---------- TEST 2.1 ---------- Validating: <MyTest2 Id="0123456789">0123456789</MyTest2> No error found ---------- TEST 2.2 ---------- Validating: <MyTest2 Id="0123456789***">0123456789</MyTest2> Validation failed: The 'Id' attribute is invalid - The value '0123456789***' is invalid according to its datatype 'MyString' - The actual length is greater than the MaxLength value. ---------- TEST 2.3 ---------- Validating: <MyTest2 Id="0123456789">0123456789***</MyTest2> Validation failed: The 'MyTest2' element is invalid - The value '0123456789***' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value. ---------- TEST 3.1 ---------- Validating: <MyTest3 Id="0123456789">0123456789</MyTest3> No error found ---------- TEST 3.2 ---------- Validating: <MyTest3 Id="0123456789***">0123456789</MyTest3> Validation failed: The 'Id' attribute is invalid - The value '0123456789***' is invalid according to its datatype 'MyString' - The actual length is greater than the MaxLength value. ---------- TEST 3.3 ---------- Validating: <MyTest3 Id="0123456789">0123456789***</MyTest3> Validation failed: The 'MyTest3' element is invalid - The value '0123456789***' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value. How often does this happen? ALWAYS!!!!!!!!!! Additional Information: Test 1.*: Id is defined by its parent, but mono didn't find the definition. Test 3.2: Mono didn't validate the facet maxLength for the element, but it actually validate maxLength for the attribute (Test 2.2/3.2) -- Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. _______________________________________________ mono-bugs maillist - mono-bugs@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-bugs