[Mono-bugs] [Bug 76925][Nor] New - XmlSchemas.Find fails to find name present in Added schemas

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Dec 5 18:16:39 EST 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by t7 at pobox.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76925

--- shadow/76925	2005-12-05 18:16:39.000000000 -0500
+++ shadow/76925.tmp.31225	2005-12-05 18:16:39.000000000 -0500
@@ -0,0 +1,181 @@
+Bug#: 76925
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: atsushi at ximian.com                            
+ReportedBy: t7 at pobox.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: XmlSchemas.Find fails to find name present in Added schemas
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+The System.Xml.Serialization.XmlSchemas class object Find (XmlQualifiedName
+name, Type type) method fails to find the name under some circumstances.
+Specifically, if two schemas are added that have the same target namespace,
+ the name passed to find will only be found if it occurs in the last
+Add()ed. (e.g. if the target namespace is the empty string).
+
+Steps to reproduce the problem:
+1. Compile test program
+2. Run it with common.xsd, A.xsd & B.xsd in the same dir
+3. 
+
+Actual Results:
+Displays: Bug: didn't find AType from A.xsd
+
+
+Expected Results:
+Should display: AType found.
+
+How often does this happen? 
+Every time
+
+Additional Information:
+The problem is that XmlSchemas uses a hash table to make a map from target
+namespace string keys to XmlSchemas.  The implementation of Find first
+looks to see if the namespace is present as a key and if so calls Find on
+that XmlSchema.  Only if the namespace isn't in the hash table does it
+search all the XmlSchemas for the name.
+Multiple XmlSchemas with the same target namespace causes the hashtable
+entries to be repeatedly re-assigned, leaving only the last XmlSchemas
+assigned to be found byt he check.
+
+There is some debate as to if this is the correct behaviour or not. 
+However, the when run on MS .NET with the test schemas provided if suceeds
+in Finding the name.
+
+If the MS behaviour is to be matched, a simple change to XmlSchemas.Find
+should be made so that if it fails to find the name in the schema that was
+in the hashtable, it looks in all schemas (or make the hashtable values,
+lists of XmlSchemas instead of single XmlSchemas)
+
+This difference in behaviour is responsible for different behaviour of the
+Mono xsd tool vs the MS xsd tool when passes multiple XSD files and the
+/classes switch.  The MS tool generates a source object binding for every
+type in every XSD (AType & BTyte in the examples below), whereas Mono xsd
+only generates the types from the last XSD on the command like (BType, but
+not AType).
+
+
+Here is the test program XmlSchemasTest.cs:
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+
+
+public class XmlSchemasTest
+{
+  public static void Main(string[] args)
+  {
+    XmlSchemas schemas = new XmlSchemas();
+
+    ValidationEventHandler validationEventHandler = new
+ValidationEventHandler(ValidationCallbackOne);
+
+
+
+    StreamReader sr = new StreamReader("A.xsd");
+    XmlSchema xmls = XmlSchema.Read (sr, validationEventHandler);
+    schemas.Add(xmls);
+    sr.Close();
+
+    sr = new StreamReader("B.xsd");
+    xmls = XmlSchema.Read (sr, validationEventHandler);
+    schemas.Add(xmls);
+    sr.Close();
+
+    XmlQualifiedName name = new XmlQualifiedName("AType");
+    object elt = schemas.Find(name,typeof (XmlSchemaElement));
+
+    if (elt == null)
+      System.Console.WriteLine("Bug: didn't find AType from A.xsd");
+    else
+      System.Console.WriteLine("AType found");
+  }
+
+
+  public static void ValidationCallbackOne(object sender,
+ValidationEventArgs args) {
+    Console.WriteLine(args.Message);
+  }
+
+
+}
+
+
+
+---
+Here is A.xsd:
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:include schemaLocation="common.xsd" />
+
+  <xs:element name="AType">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="CType1">
+          <xs:sequence>
+            <xs:element name="f1" type="xs:boolean" />
+            <xs:element name="f2" type="SType1" />
+          </xs:sequence>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
+
+
+----
+Here is B.xsd:
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:include schemaLocation="common.xsd" />
+
+  <xs:element name="BType">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="CType1">
+          <xs:sequence>
+            <xs:element name="bf1" type="xs:boolean" />
+            <xs:element name="bf2" type="SType1" />
+          </xs:sequence>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
+
+
+---
+and here is common.xsd:
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+        <xs:complexType name="CType1">
+                <xs:sequence>
+                        <xs:element name="src" type="xs:string"/>
+                </xs:sequence>
+        </xs:complexType>
+
+
+  <xs:simpleType name="SType1">
+    <xs:restriction base="xs:string">
+      <xs:enumeration value="Value1"/>
+      <xs:enumeration value="Value2"/>
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>


More information about the mono-bugs mailing list