2006-11-09 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 9 Nov 2006 09:07:40 +0000 (09:07 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 9 Nov 2006 09:07:40 +0000 (09:07 -0000)
* XmlSchemaImporter.cs : attributes might overlap by extending
  base content models. Since invalid content models are rejected by
  Compile(), simply ignore duplicating attributes. Note that it is
  basically hack, which should not skip derived ones but use them (but
  it is mostly harmless since the result is very unlikely to differ).

* XmlSchemaImporterTests.cs :
  added ImportComplexDerivationByExtension().

svn path=/trunk/mcs/; revision=67581

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaImporterTests.cs

index 6acbe61c56e07b64b975cb1086b7c01911f34607..fa9a263991c0af669df5b902a6ec2cad4be08805 100644 (file)
@@ -1,3 +1,11 @@
+2006-11-09  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlSchemaImporter.cs : attributes might overlap by extending
+         base content models. Since invalid content models are rejected by
+         Compile(), simply ignore duplicating attributes. Note that it is
+         basically hack, which should not skip derived ones but use them (but
+         it is mostly harmless since the result is very unlikely to differ).
+
 2006-11-08  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlSchemaImporter.cs : when top-level element is xs:anyType, all
index 35360517a90788218659e7726bf0a773461357a1..fb5255dc7bb4289a17d651b488796c49cbc88df8 100644 (file)
@@ -686,6 +686,8 @@ namespace System.Xml.Serialization
                
                void ImportAttributes (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat, CodeIdentifiers classIds)
                {
+                       atts = CollectAttributeUsesNonOverlap (atts, cmap);
+
                        if (anyat != null)
                        {
                        XmlTypeMapMemberAnyAttribute member = new XmlTypeMapMemberAnyAttribute ();
@@ -727,6 +729,20 @@ namespace System.Xml.Serialization
                        }
                }
 
+               // Attributes might be redefined, so there is an existing attribute for the same name, skip it.
+               // FIXME: this is nothing more than just a hack.
+               // Basically it should use
+               // XmlSchemaComplexType.AttributeUses.
+               XmlSchemaObjectCollection CollectAttributeUsesNonOverlap (
+                       XmlSchemaObjectCollection src, ClassMap map)
+               {
+                       XmlSchemaObjectCollection atts = new XmlSchemaObjectCollection ();
+                       foreach (XmlSchemaAttribute a in src)
+                               if (map.GetAttribute (a.QualifiedName.Name, a.QualifiedName.Namespace) == null)
+                                       atts.Add (a);
+                       return atts;
+               }
+
                ListMap BuildArrayMap (XmlQualifiedName typeQName, XmlSchemaComplexType stype, out TypeData arrayTypeData)
                {
                        if (encodedFormat)
@@ -1628,7 +1644,7 @@ namespace System.Xml.Serialization
                        }
                        else
                        {
-                               ns = typeQName.Namespace;
+                               ns = attr.ParentIsSchema ? typeQName.Namespace : String.Empty;
                                return attr;
                        }
                }
index 5522d47be155b3fd5da577b1251b25b519a0a839..866a718a3406b6cdd4ec7b50781585bd2d4d2ab5 100644 (file)
@@ -1,3 +1,8 @@
+2006-11-09  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlSchemaImporterTests.cs :
+         added ImportComplexDerivationByExtension().
+
 2006-11-08  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlSchemaImporterTests.cs :
index 60ff44b4ed31afb2bdbd83aea767951ed106a20f..80277899b741e39e32c9cdf3d8ca34748ab3e2e3 100644 (file)
@@ -3,10 +3,33 @@
 //
 // Author:
 //   Gert Driesen (drieseng@users.sourceforge.net)
+//   Atsushi Enomoto (atsushi@ximian.com)
 //
-// (C) 2005 Novell
+// (C) 2005 Gert Driesen
+// Copyright (C) 2006 Novell, Inc.
 // 
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.CodeDom;
 using System.Collections;
@@ -1035,5 +1058,29 @@ namespace MonoTests.System.XmlSerialization
                        Assert.IsTrue (foo, "FooType not found");
                        Assert.IsTrue (bar, "BarType not found");
                }
+
+               [Test]
+               public void ImportComplexDerivationByExtension ()
+               {
+                       string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+  <xs:element name='Root' type='DerivedType' />
+  <xs:complexType name='DerivedType'>
+    <xs:complexContent>
+      <xs:extension base='BaseType'>
+        <xs:attribute name='Foo' type='xs:string' />
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+  <xs:complexType name='BaseType'>
+    <xs:attribute name='Foo' type='xs:string' />
+  </xs:complexType>
+</xs:schema>";
+                       XmlSchemas xss = new XmlSchemas ();
+                       xss.Add (XmlSchema.Read (new XmlTextReader (new StringReader (xsd)), null));
+                       XmlSchemaImporter imp = new XmlSchemaImporter (xss);
+                       CodeNamespace cns = new CodeNamespace ();
+                       XmlCodeExporter exp = new XmlCodeExporter (cns);
+                       exp.ExportTypeMapping (imp.ImportTypeMapping (new XmlQualifiedName ("Root")));
+               }
        }
 }