* MapCodeGenerator.cs: Added helper method for generating an attribute
authorLluis Sanchez <lluis@novell.com>
Tue, 27 Jan 2004 12:43:22 +0000 (12:43 -0000)
committerLluis Sanchez <lluis@novell.com>
Tue, 27 Jan 2004 12:43:22 +0000 (12:43 -0000)
  parameter of type enum.
* XmlAttributeAttribute.cs: little fix.
* XmlCodeExporter.cs: Support XmlAnyAttribute when generating attributes
  for method parameters.
* XmlMemberMapping.cs: Improved support for members of type "any".
* XmlReflectionImporter.cs: Improved assignment of the attribute form.
  If the namespace is explicitly specified, then the form should be
  qualified. Also fixed issues with the namespace assigned to attributes.
  This should fix bug #53384.
* XmlSchemaExporter.cs: ExportMembersMapping(): improved support for
  methods that return values of type "any". Changed the methods
  AddSchemaArrayElement and AddSchemaElement, so instead of adding the
  element, return it, and the caller must add it to the collection.
  Other fixes in attribute generation.
* XmlSchemaImporter.cs: ImportAnyType(): if a type name is provided,
  generate the AnyType mapping from the type described in the schema.
  Small fixes regarding IsMixed property of complex types (it means that
  the type can contain text, so the XmlTextAttribute must be generated).
* XmlSerializationReaderInterpreter.cs: Reading of members by-order must
  be only used in the bare+encoded format.

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

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
mcs/class/System.XML/System.Xml.Serialization/XmlAttributeAttribute.cs
mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlMemberMapping.cs
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs

index 7a7a04163ca9b43d712a4302dea71ba533bce85c..389f925996fedf065e151c859227e39e2ab7615b 100755 (executable)
@@ -1,3 +1,27 @@
+2004-01-27  Lluis Sanchez Gual  <lluis@ximian.com>
+
+       * MapCodeGenerator.cs: Added helper method for generating an attribute
+         parameter of type enum.
+       * XmlAttributeAttribute.cs: little fix.
+       * XmlCodeExporter.cs: Support XmlAnyAttribute when generating attributes
+         for method parameters.
+       * XmlMemberMapping.cs: Improved support for members of type "any".
+       * XmlReflectionImporter.cs: Improved assignment of the attribute form.
+         If the namespace is explicitly specified, then the form should be
+         qualified. Also fixed issues with the namespace assigned to attributes.
+         This should fix bug #53384.
+       * XmlSchemaExporter.cs: ExportMembersMapping(): improved support for
+         methods that return values of type "any". Changed the methods
+         AddSchemaArrayElement and AddSchemaElement, so instead of adding the
+         element, return it, and the caller must add it to the collection.
+         Other fixes in attribute generation.
+       * XmlSchemaImporter.cs: ImportAnyType(): if a type name is provided,
+         generate the AnyType mapping from the type described in the schema.
+         Small fixes regarding IsMixed property of complex types (it means that
+         the type can contain text, so the XmlTextAttribute must be generated).
+       * XmlSerializationReaderInterpreter.cs: Reading of members by-order must
+         be only used in the bare+encoded format.
+
 2004-01-24  Lluis Sanchez Gual  <lluis@ximian.com>
 
        * SoapReflectionImporter.cs: Types included with SoapInclude don't need
index 5db0ed79ea6abbcbfa79dea774b1d52f5c8211f2..c439b31550ece0b99a3128443752da758c83543c 100644 (file)
@@ -371,6 +371,11 @@ namespace System.Xml.Serialization {
                        return new CodeAttributeArgument (name, new CodeTypeOfExpression(typeName));
                }
 
+               public CodeAttributeArgument GetEnumArg (string name, string enumType, string enumValue)
+               {
+                       return new CodeAttributeArgument (name, new CodeFieldReferenceExpression (new CodeTypeReferenceExpression(enumType), enumValue));
+               }
+               
                public static void AddComments (CodeTypeMember member, string comments)
                {
                        if (comments == null || comments == "") member.Comments.Add (new CodeCommentStatement ("<remarks/>", true));
index e23ff75890c76c3d4a8d52edb59340200c8d6d3a..858297687bf9ecc8a0ad1064dc6516fd3083c9e6 100644 (file)
@@ -66,7 +66,6 @@ namespace System.Xml.Serialization
                                return form;
                        }\r
                        set {
-                               if(Namespace != null)
                                form = value;
                        }\r
                }\r
index da92794df5e69658cfeab25a634e5756d2b228a9..b5bdcaa5803d4a60acc93aa23aa90fecd58b0e68 100644 (file)
@@ -70,7 +70,24 @@ namespace System.Xml.Serialization {
                        CodeAttributeDeclaration att;\r
                        TypeData memType = member.TypeMapMember.TypeData;\r
                        \r
-                       if (memType.SchemaType == SchemaTypes.Array)\r
+                       if (member.Any)\r
+                       {\r
+                               XmlTypeMapElementInfoList list = (XmlTypeMapElementInfoList)((XmlTypeMapMemberElement)member.TypeMapMember).ElementInfo;\r
+                               foreach (XmlTypeMapElementInfo info in list)\r
+                               {\r
+                                       if (info.IsTextElement)\r
+                                               metadata.Add (new CodeAttributeDeclaration ("System.Xml.Serialization.XmlText"));\r
+                                       else {\r
+                                               att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlAnyElement");\r
+                                               if (!info.IsUnnamedAnyElement) {\r
+                                                       att.Arguments.Add (MapCodeGenerator.GetArg ("Name", info.ElementName));\r
+                                                       if (info.Namespace != ns) att.Arguments.Add (MapCodeGenerator.GetArg ("Namespace", member.Namespace));\r
+                                               }\r
+                                               metadata.Add (att);\r
+                                       }\r
+                               }\r
+                       }\r
+                       else if (memType.SchemaType == SchemaTypes.Array)\r
                        {\r
                                // Array parameter\r
                                att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlArray");\r
@@ -144,7 +161,7 @@ namespace System.Xml.Serialization {
                        CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlAttribute");\r
                        if (attinfo.Name != attinfo.AttributeName) att.Arguments.Add (GetArg (attinfo.AttributeName));\r
                        if (attinfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", attinfo.Namespace));\r
-                       if (attinfo.Form != XmlSchemaForm.None) att.Arguments.Add (GetArg ("Form",attinfo.Form));\r
+                       if (attinfo.Form != XmlSchemaForm.None) att.Arguments.Add (GetEnumArg ("Form","System.Xml.Schema.XmlSchemaForm",attinfo.Form.ToString()));\r
                        if (!TypeTranslator.IsDefaultPrimitiveTpeData(attinfo.TypeData)) att.Arguments.Add (GetArg ("DataType",attinfo.TypeData.XmlType));\r
                        AddCustomAttribute (codeField, att, true);\r
                }\r
index b928412f1e780a819a723d494558f445dc91f429..3658091f44ca1bf567e7b38312a5fa073e89d3ff 100644 (file)
@@ -23,7 +23,16 @@ namespace System.Xml.Serialization
                        _mapMember = mapMem;
                        _memberName = memberName;
 
-                       if (mapMem is XmlTypeMapMemberElement)
+                       if (mapMem is XmlTypeMapMemberAnyElement)
+                       {
+                               XmlTypeMapMemberAnyElement anyelem = (XmlTypeMapMemberAnyElement) mapMem;
+                               XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) anyelem.ElementInfo[anyelem.ElementInfo.Count-1];
+                               _elementName = info.ElementName;
+                               _namespace = info.Namespace;
+                               if (info.MappedType != null) _typeNamespace = info.MappedType.Namespace;
+                               else _typeNamespace = "";
+                       }
+                       else if (mapMem is XmlTypeMapMemberElement)
                        {
                                XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)mapMem).ElementInfo[0];
                                _elementName = info.ElementName;
index 3ba928337a79de830f0f412225159aaa92a05476..ada432ac61104d8b480b70c1687b781b01b49fea 100644 (file)
@@ -12,6 +12,7 @@
 
 using System.Reflection;
 using System.Collections;
+using System.Xml.Schema;
 
 namespace System.Xml.Serialization {
        public class XmlReflectionImporter {
@@ -540,7 +541,7 @@ namespace System.Xml.Serialization {
                                         (rmember.MemberType.FullName == "System.Xml.XmlElement"))
                                {
                                        XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement();
-                                       member.ElementInfo = ImportAnyElementInfo (defaultNamespace, rmember.MemberType, member, atts);
+                                       member.ElementInfo = ImportAnyElementInfo (defaultNamespace, rmember, member, atts);
                                        mapMember = member;
                                }
                                else
@@ -564,11 +565,25 @@ namespace System.Xml.Serialization {
                                else 
                                        mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;
 
-                               mapAttribute.Form = atts.XmlAttribute.Form;
-                               mapAttribute.Namespace = (atts.XmlAttribute.Namespace != null) ? atts.XmlAttribute.Namespace : "";
                                if (typeData.IsComplexType)
                                        mapAttribute.MappedType = ImportTypeMapping (typeData.Type, null, mapAttribute.Namespace);
-
+                               
+                               if (atts.XmlAttribute.Namespace != null && atts.XmlAttribute.Namespace != defaultNamespace)
+                               {
+                                       if (atts.XmlAttribute.Form == XmlSchemaForm.Unqualified)
+                                               throw new InvalidOperationException ("The Form property may not be 'Unqualified' when an explicit Namespace property is present");
+                                       mapAttribute.Form = XmlSchemaForm.Qualified;
+                                       mapAttribute.Namespace = atts.XmlAttribute.Namespace;
+                               }
+                               else
+                               {
+                                       mapAttribute.Form = atts.XmlAttribute.Form;
+                                       if (atts.XmlAttribute.Form == XmlSchemaForm.Qualified)
+                                               mapAttribute.Namespace = defaultNamespace;
+                                       else
+                                               mapAttribute.Namespace = "";
+                               }
+                               
                                typeData = TypeTranslator.GetTypeData(rmember.MemberType, atts.XmlAttribute.DataType);
                                mapMember = mapAttribute;
                        }
@@ -671,18 +686,27 @@ namespace System.Xml.Serialization {
                        return list;
                }
 
-               XmlTypeMapElementInfoList ImportAnyElementInfo (string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
+               XmlTypeMapElementInfoList ImportAnyElementInfo (string defaultNamespace, XmlReflectionMember rmember, XmlTypeMapMemberElement member, XmlAttributes atts)
                {
                        XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
 
-                       ImportTextElementInfo (list, defaultType, member, atts);
+                       ImportTextElementInfo (list, rmember.MemberType, member, atts);
 
                        foreach (XmlAnyElementAttribute att in atts.XmlAnyElements)
                        {
                                XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(typeof(XmlElement)));
-                               if (att.Name != null && att.Name != string.Empty) elem.ElementName = att.Name;
-                               else elem.IsUnnamedAnyElement = true;
-                               elem.Namespace = (att.Namespace != null) ? att.Namespace : "";
+                               if (att.Name != null && att.Name != string.Empty) 
+                               {
+                                       elem.ElementName = att.Name;
+                                       elem.Namespace = (att.Namespace != null) ? att.Namespace : "";
+                               }
+                               else 
+                               {
+                                       elem.IsUnnamedAnyElement = true;
+                                       elem.Namespace = defaultNamespace;
+                                       if (att.Namespace != null) 
+                                               throw new InvalidOperationException ("The element " + rmember.MemberName + " has been attributed with an XmlAnyElementAttribute and a namespace '" + att.Namespace + "', but no name. When a namespace is supplied, a name is also required. Supply a name or remove the namespace.");
+                               }
                                list.Add (elem);
                        }
                        return list;
index 039e053ab25fb9753d9ab1f87c50709923699e7c..dc686344222bfb30a25aac5e66068b6281b6a715 100644 (file)
@@ -55,11 +55,11 @@ namespace System.Xml.Serialization {
                
                internal void ExportMembersMapping (XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
                {
-                       XmlSchema schema = GetSchema (xmlMembersMapping.Namespace);
                        ClassMap cmap = (ClassMap) xmlMembersMapping.ObjectMap;
 
                        if (xmlMembersMapping.HasWrapperElement && exportEnclosingType)
                        {
+                               XmlSchema schema = GetSchema (xmlMembersMapping.Namespace);
                                XmlSchemaComplexType stype = new XmlSchemaComplexType ();
        
                                XmlSchemaSequence particle;
@@ -86,31 +86,63 @@ namespace System.Xml.Serialization {
                                ICollection members = cmap.ElementMembers;
                                if (members != null)
                                {
-                                       XmlSchemaObjectCollection itemsCol = schema.Items;
-                                       
-                                       // In encoded format, the schema elements are not needed
-                                       if (encodedFormat) itemsCol = new XmlSchemaObjectCollection ();
-                                       
                                        foreach (XmlTypeMapMemberElement member in members)
                                        {
-                                               XmlSchemaElement exe = FindElement (itemsCol, ((XmlTypeMapElementInfo)member.ElementInfo [0]).ElementName);
+                                               if (member is XmlTypeMapMemberAnyElement && member.TypeData.IsListType)
+                                               {
+                                                       XmlSchema mschema = GetSchema (xmlMembersMapping.Namespace);
+                                                       XmlSchemaParticle par = GetSchemaArrayElement (mschema, member.ElementInfo);
+                                                       if (par is XmlSchemaAny)
+                                                       {
+                                                               XmlSchemaComplexType ct = FindComplexType (mschema.Items, "any");
+                                                               if (ct != null) continue;
+                                                               
+                                                               ct = new XmlSchemaComplexType ();
+                                                               ct.Name = "any";
+                                                               ct.IsMixed = true;
+                                                               XmlSchemaSequence seq = new XmlSchemaSequence ();
+                                                               ct.Particle = seq;
+                                                               seq.Items.Add (par);
+                                                               mschema.Items.Add (ct);
+                                                               continue;
+                                                       }
+                                               }
+                                               
+                                               
+                                               XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) member.ElementInfo [0];
+                                               XmlSchema schema;
+
+                                               if (encodedFormat)
+                                               {
+                                                       schema = GetSchema (xmlMembersMapping.Namespace);
+                                                       ImportNamespace (schema, XmlSerializer.EncodingNamespace);
+                                               }
+                                               else
+                                                       schema = GetSchema (einfo.Namespace);
+                                               
+                                               
+                                               XmlSchemaElement exe = FindElement (schema.Items, einfo.ElementName);
                                                XmlSchemaElement elem;
                                                
                                                Type memType = member.GetType();
                                                if (member is XmlTypeMapMemberFlatList)
                                                        throw new InvalidOperationException ("Unwrapped arrays not supported as parameters");
                                                else if (memType == typeof(XmlTypeMapMemberElement))
-                                                       elem = (XmlSchemaElement) AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, false);
+                                                       elem = (XmlSchemaElement) GetSchemaElement (schema, einfo, member.DefaultValue, false);
                                                else
-                                                       elem = (XmlSchemaElement) AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], false);
-                                                       
+                                                       elem = (XmlSchemaElement) GetSchemaElement (schema, einfo, false);
+                                               
+                                               // In encoded format, the schema elements are not needed
+                                               if (!encodedFormat)
+                                                       schema.Items.Add (elem);
+                                               
                                                if (exe != null)
                                                {
                                                        if (exe.SchemaTypeName.Equals (elem.SchemaTypeName))
-                                                               itemsCol.Remove (elem);
+                                                               schema.Items.Remove (elem);
                                                        else
                                                        {
-                                                               string s = "The XML element named '" + ((XmlTypeMapElementInfo)member.ElementInfo [0]).ElementName + "' ";
+                                                               string s = "The XML element named '" + einfo.ElementName + "' ";
                                                                s += "from namespace '" + schema.TargetNamespace + "' references distinct types " + elem.SchemaTypeName.Name + " and " + exe.SchemaTypeName.Name + ". ";
                                                                s += "Use XML attributes to specify another XML name or namespace for the element or types.";
                                                                throw new InvalidOperationException (s);
@@ -120,9 +152,6 @@ namespace System.Xml.Serialization {
                                }
                        }
                        
-                       if (encodedFormat) 
-                               ImportNamespace (schema, XmlSerializer.EncodingNamespace);
-                               
                        CompileSchemas ();
                }
 
@@ -152,7 +181,7 @@ namespace System.Xml.Serialization {
                                if (xmlTypeMapping.TypeData.IsComplexType)
                                        einfo.MappedType = xmlTypeMapping;
                                einfo.IsNullable = false;
-                               AddSchemaElement (schema.Items, schema, einfo, false);
+                               schema.Items.Add (GetSchemaElement (schema, einfo, false));
                                SetElementExported (xmlTypeMapping);
                        }
                        
@@ -232,19 +261,19 @@ namespace System.Xml.Serialization {
                                        Type memType = member.GetType();
                                        if (memType == typeof(XmlTypeMapMemberFlatList))
                                        {
-                                               AddSchemaArrayElement (seq.Items, schema, member.ElementInfo);
+                                               seq.Items.Add (GetSchemaArrayElement (schema, member.ElementInfo));
                                        }
                                        else if (memType == typeof(XmlTypeMapMemberAnyElement))
                                        {
-                                               AddSchemaArrayElement (seq.Items, schema, member.ElementInfo);
+                                               seq.Items.Add (GetSchemaArrayElement (schema, member.ElementInfo));
                                        }
                                        else if (memType == typeof(XmlTypeMapMemberElement))
                                        {
-                                               XmlSchemaElement selem = (XmlSchemaElement) AddSchemaElement (seq.Items, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, true);
+                                               seq.Items.Add (GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, true));
                                        }
                                        else
                                        {
-                                               AddSchemaElement (seq.Items, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], true);
+                                               seq.Items.Add (GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo [0], true));
                                        }
                                }
                        }
@@ -259,7 +288,7 @@ namespace System.Xml.Serialization {
                        {
                                foreach (XmlTypeMapMemberAttribute attr in attributes) {
                                        if (baseMap != null && DefinedInBaseMap (baseMap, attr)) continue;
-                                       outAttributes.Add (GetSchemaAttribute (schema, attr));
+                                       outAttributes.Add (GetSchemaAttribute (schema, attr, true));
                                }
                        }
 
@@ -280,17 +309,33 @@ namespace System.Xml.Serialization {
                        return null;
                }
 
-               XmlSchemaAttribute GetSchemaAttribute (XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo)
+               XmlSchemaComplexType FindComplexType (XmlSchemaObjectCollection col, string name)
+               {
+                       foreach (XmlSchemaObject ob in col)
+                       {
+                               XmlSchemaComplexType ctype = ob as XmlSchemaComplexType;
+                               if (ctype != null && ctype.Name == name) return ctype;
+                       }
+                       return null;
+               }
+
+               XmlSchemaAttribute GetSchemaAttribute (XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo, bool isTypeMember)
                {
                        XmlSchemaAttribute sat = new XmlSchemaAttribute ();
                        if (attinfo.DefaultValue != System.DBNull.Value) sat.DefaultValue = XmlCustomFormatter.ToXmlString (attinfo.TypeData, attinfo.DefaultValue);
 
                        ImportNamespace (currentSchema, attinfo.Namespace);
 
-                       XmlSchema memberSchema = GetSchema (attinfo.Namespace);
+                       XmlSchema memberSchema;
+                       if (attinfo.Namespace.Length == 0 && attinfo.Form != XmlSchemaForm.Qualified)
+                               memberSchema = currentSchema;
+                       else
+                               memberSchema = GetSchema (attinfo.Namespace);
+
                        if (currentSchema == memberSchema || encodedFormat)
                        {
                                sat.Name = attinfo.AttributeName;
+                               if (isTypeMember) sat.Form = attinfo.Form;
                                if (attinfo.TypeData.SchemaType == SchemaTypes.Enum)
                                {
                                        ImportNamespace (currentSchema, attinfo.DataTypeNamespace);
@@ -311,17 +356,17 @@ namespace System.Xml.Serialization {
                                        if (ob is XmlSchemaAttribute && ((XmlSchemaAttribute)ob).Name == attinfo.AttributeName)
                                                return sat;
                                                
-                               memberSchema.Items.Add (GetSchemaAttribute (memberSchema, attinfo));
+                               memberSchema.Items.Add (GetSchemaAttribute (memberSchema, attinfo, false));
                        }
                        return sat;
                }
 
-               XmlSchemaParticle AddSchemaElement (XmlSchemaObjectCollection destcol, XmlSchema currentSchema, XmlTypeMapElementInfo einfo, bool isTypeMember)
+               XmlSchemaParticle GetSchemaElement (XmlSchema currentSchema, XmlTypeMapElementInfo einfo, bool isTypeMember)
                {
-                       return AddSchemaElement (destcol, currentSchema, einfo, System.DBNull.Value, isTypeMember);
+                       return GetSchemaElement (currentSchema, einfo, System.DBNull.Value, isTypeMember);
                }
                
-               XmlSchemaParticle AddSchemaElement (XmlSchemaObjectCollection destcol, XmlSchema currentSchema, XmlTypeMapElementInfo einfo, object defaultValue, bool isTypeMember)
+               XmlSchemaParticle GetSchemaElement (XmlSchema currentSchema, XmlTypeMapElementInfo einfo, object defaultValue, bool isTypeMember)
                {
                        if (einfo.IsTextElement) return null;
 
@@ -330,12 +375,10 @@ namespace System.Xml.Serialization {
                                XmlSchemaAny any = new XmlSchemaAny ();
                                any.MinOccurs = 0;
                                any.MaxOccurs = 1;
-                               destcol.Add (any);
                                return any;
                        }
                        
                        XmlSchemaElement selem = new XmlSchemaElement ();
-                       destcol.Add (selem);
 
                        if (isTypeMember)
                        {
@@ -407,7 +450,7 @@ namespace System.Xml.Serialization {
                                        if (ob is XmlSchemaElement && ((XmlSchemaElement)ob).Name == einfo.ElementName)
                                                return selem;
                                                
-                               AddSchemaElement (memberSchema.Items, memberSchema, einfo, defaultValue, false);
+                               memberSchema.Items.Add (GetSchemaElement (memberSchema, einfo, defaultValue, false));
                        }
                        return selem;
                }
@@ -466,7 +509,7 @@ namespace System.Xml.Serialization {
                        return stype;
                }
 
-               XmlSchemaParticle AddSchemaArrayElement (XmlSchemaObjectCollection destcol, XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
+               XmlSchemaParticle GetSchemaArrayElement (XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
                {
                        int numInfos = infos.Count;
                        if (numInfos > 0 && ((XmlTypeMapElementInfo)infos[0]).IsTextElement) numInfos--;
@@ -474,7 +517,7 @@ namespace System.Xml.Serialization {
 
                        if (numInfos == 1)
                        {
-                               XmlSchemaParticle selem = AddSchemaElement (destcol, currentSchema, (XmlTypeMapElementInfo) infos[infos.Count-1], true);
+                               XmlSchemaParticle selem = GetSchemaElement (currentSchema, (XmlTypeMapElementInfo) infos[infos.Count-1], true);
                                selem.MinOccursString = "0";
                                selem.MaxOccursString = "unbounded";
                                return selem;
@@ -482,13 +525,12 @@ namespace System.Xml.Serialization {
                        else
                        {
                                XmlSchemaChoice schoice = new XmlSchemaChoice ();
-                               destcol.Add (schoice);
                                schoice.MinOccursString = "0";
                                schoice.MaxOccursString = "unbounded";
                                foreach (XmlTypeMapElementInfo einfo in infos)
                                {
                                        if (einfo.IsTextElement) continue;
-                                       AddSchemaElement (schoice.Items, currentSchema, einfo, true);
+                                       schoice.Items.Add (GetSchemaElement (currentSchema, einfo, true));
                                }
                                return schoice;
                        }
@@ -582,12 +624,15 @@ namespace System.Xml.Serialization {
                                stype.Name = map.ElementName;
                                schema.Items.Add (stype);
 
-                               XmlSchemaSequence seq = new XmlSchemaSequence ();
-                               XmlSchemaParticle spart = AddSchemaArrayElement (seq.Items, schema, lmap.ItemInfo);
+                               XmlSchemaParticle spart = GetSchemaArrayElement (schema, lmap.ItemInfo);
                                if (spart is XmlSchemaChoice)
                                        stype.Particle = spart;
                                else
+                               {
+                                       XmlSchemaSequence seq = new XmlSchemaSequence ();
+                                       seq.Items.Add (spart);
                                        stype.Particle = seq;
+                               }
                                        
                                return new XmlQualifiedName (map.XmlType, map.XmlTypeNamespace);
                        }
index fa4dfa440fd7c5f8234fff58589ec6e2f96fcd97..bc28e5e7c2632e07bc5a8eec5d5aa61deefd9743 100644 (file)
@@ -72,14 +72,37 @@ namespace System.Xml.Serialization {
 \r
                public XmlMembersMapping ImportAnyType (XmlQualifiedName typeName, string elementName)\r
                {\r
-                       XmlTypeMapMemberAnyElement mapMem = new XmlTypeMapMemberAnyElement ();\r
-                       mapMem.Name = typeName.Name;\r
-                       mapMem.TypeData = TypeTranslator.GetTypeData(typeof(XmlNode));\r
-                       mapMem.ElementInfo.Add (CreateElementInfo (typeName.Namespace, mapMem, typeName.Name, mapMem.TypeData, true));\r
-                       \r
-                       XmlMemberMapping[] mm = new XmlMemberMapping [1];\r
-                       mm[0] = new XmlMemberMapping (typeName.Name, typeName.Namespace, mapMem, encodedFormat);\r
-                       return new XmlMembersMapping (mm);\r
+                       if (typeName == XmlQualifiedName.Empty)\r
+                       {\r
+                               XmlTypeMapMemberAnyElement mapMem = new XmlTypeMapMemberAnyElement ();\r
+                               mapMem.Name = typeName.Name;\r
+                               mapMem.TypeData = TypeTranslator.GetTypeData(typeof(XmlNode));\r
+                               mapMem.ElementInfo.Add (CreateElementInfo (typeName.Namespace, mapMem, typeName.Name, mapMem.TypeData, true));\r
+                               \r
+                               XmlMemberMapping[] mm = new XmlMemberMapping [1];\r
+                               mm[0] = new XmlMemberMapping (typeName.Name, typeName.Namespace, mapMem, encodedFormat);\r
+                               return new XmlMembersMapping (mm);\r
+                       }\r
+                       else\r
+                       {\r
+                               XmlSchemaComplexType stype = (XmlSchemaComplexType) schemas.Find (typeName, typeof (XmlSchemaComplexType));\r
+                               if (stype == null) \r
+                                       throw new InvalidOperationException ("Referenced type '" + typeName + "' not found");\r
+                               \r
+                               if (!CanBeAnyElement (stype))\r
+                                       throw new InvalidOperationException ("The type '" + typeName + "' is not valid for a collection of any elements");\r
+                                       \r
+                               ClassMap cmap = new ClassMap ();\r
+                               CodeIdentifiers classIds = new CodeIdentifiers ();\r
+                               bool isMixed = stype.IsMixed;\r
+                               ImportSequenceContent (typeName, cmap, ((XmlSchemaSequence) stype.Particle).Items, classIds, false, ref isMixed);\r
+                               XmlTypeMapMemberAnyElement mapMem = (XmlTypeMapMemberAnyElement) cmap.AllMembers[0];\r
+                               mapMem.Name = typeName.Name;\r
+                               \r
+                               XmlMemberMapping[] mm = new XmlMemberMapping [1];\r
+                               mm[0] = new XmlMemberMapping (typeName.Name, typeName.Namespace, mapMem, encodedFormat);\r
+                               return new XmlMembersMapping (mm);\r
+                       }\r
                }\r
 \r
                public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, Type baseType)\r
@@ -329,7 +352,10 @@ namespace System.Xml.Serialization {
                        }\r
                        else if (CanBeAnyElement (stype))\r
                        {\r
-                               return GetTypeMapping (TypeTranslator.GetTypeData(typeof(XmlElement)));\r
+                               if (stype.IsMixed)\r
+                                       return GetTypeMapping (TypeTranslator.GetTypeData(typeof(XmlNode)));\r
+                               else\r
+                                       return GetTypeMapping (TypeTranslator.GetTypeData(typeof(XmlElement)));\r
                        }\r
                        else if (CanBeIXmlSerializable (stype))\r
                        {\r
@@ -498,7 +524,7 @@ namespace System.Xml.Serialization {
                        {\r
                                ClassMap cmap = new ClassMap ();\r
                                CodeIdentifiers classIds = new CodeIdentifiers();\r
-                               ImportParticleComplexContent (typeQName, cmap, stype.Particle, classIds, false);\r
+                               ImportParticleComplexContent (typeQName, cmap, stype.Particle, classIds, stype.IsMixed);\r
        \r
                                XmlTypeMapMemberFlatList list = (cmap.AllMembers.Count == 1) ? cmap.AllMembers[0] as XmlTypeMapMemberFlatList : null;\r
                                if (list != null && list.ChoiceMember == null)\r
@@ -659,9 +685,9 @@ namespace System.Xml.Serialization {
                                        XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement ();\r
                                        member.Name = classIds.AddUnique ("Any", member);\r
                                        member.Documentation = GetDocumentation (elem);\r
-\r
+                                       \r
                                        Type ctype;\r
-                                       if (elem.MaxOccurs > 1 || multiValue)\r
+                                       if (elem.MaxOccurs != 1 || multiValue)\r
                                                ctype = isMixed ? typeof(XmlNode[]) : typeof(XmlElement[]);\r
                                        else\r
                                                ctype = isMixed ? typeof(XmlNode) : typeof(XmlElement);\r
@@ -686,8 +712,7 @@ namespace System.Xml.Serialization {
                                }\r
                        }\r
                }\r
-\r
-\r
+               \r
                void ImportChoiceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaChoice choice, CodeIdentifiers classIds, bool multiValue)\r
                {\r
                        XmlTypeMapElementInfoList choices = new XmlTypeMapElementInfoList ();\r
@@ -1282,7 +1307,9 @@ namespace System.Xml.Serialization {
                        if (!attr.RefName.IsEmpty)\r
                        {\r
                                ns = attr.RefName.Namespace;\r
-                               return FindRefAttribute (attr.RefName);\r
+                               XmlSchemaAttribute at = FindRefAttribute (attr.RefName);\r
+                               if (at == null) throw new InvalidOperationException ("The attribute " + attr.RefName + " is missing");\r
+                               return at;\r
                        }\r
                        else\r
                        {\r
index 0539b818198fddb60f51f7ef617cfef6544837e2..f8aa4782d6e2b6a43ebf7895d2401b8db0c70b36 100644 (file)
@@ -122,7 +122,7 @@ namespace System.Xml.Serialization
                                }
                        }
                        else
-                               ReadMembers ((ClassMap)typeMap.ObjectMap, parameters, true, true);
+                               ReadMembers ((ClassMap)typeMap.ObjectMap, parameters, true, _format == SerializationFormat.Encoded);
 
                        if (_format == SerializationFormat.Encoded)
                                ReadReferencedElements();