Przeglądaj źródła

* XmlCodeExporter.cs: Little fix.
* XmlSchemaExporter.cs: In rpc format, make sure that parameters with the
same name have the same type.
* XmlSchemaImporter.cs: Support xml:lang.
* XmlSerializationReader.cs, XmlSerializationWriterInterpreter.cs:
fixed wrong namespace for the arrayType attribute.

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

Lluis Sanchez 22 lat temu
rodzic
commit
ce97eef8b3

+ 4 - 0
mcs/class/System.XML/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,7 @@
+2003-12-11  Lluis Sanchez Gual <[email protected]>
+	
+	* 
+	
 2003-12-08  Lluis Sanchez Gual <[email protected]>
 
 	* SoapReflectionImporter.cs, XmlMembersMapping.cs, XmlReflectionImporter.cs,

+ 1 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs

@@ -210,7 +210,7 @@ namespace System.Xml.Serialization {
 		protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)
 		{
 			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");
-			if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("Name", map.ElementName));
+			if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.ElementName));
 			if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));
 			AddCustomAttribute (codeEnum, att, false);
 		}		

+ 28 - 2
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs

@@ -93,13 +93,29 @@ namespace System.Xml.Serialization {
 					
 					foreach (XmlTypeMapMemberElement member in members)
 					{
+						XmlSchemaElement exe = FindElement (itemsCol, ((XmlTypeMapElementInfo)member.ElementInfo [0]).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))
-							AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, false);
+							elem = (XmlSchemaElement) AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, false);
 						else
-							AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], false);
+							elem = (XmlSchemaElement) AddSchemaElement (itemsCol, schema, (XmlTypeMapElementInfo) member.ElementInfo [0], false);
+							
+						if (exe != null)
+						{
+							if (exe.SchemaTypeName.Equals (elem.SchemaTypeName))
+								itemsCol.Remove (elem);
+							else
+							{
+								string s = "The XML element named '" + ((XmlTypeMapElementInfo)member.ElementInfo [0]).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);
+							}
+						}
 					}
 				}
 			}
@@ -253,6 +269,16 @@ namespace System.Xml.Serialization {
 			else
 				anyAttribute = null;
 		}
+		
+		XmlSchemaElement FindElement (XmlSchemaObjectCollection col, string name)
+		{
+			foreach (XmlSchemaObject ob in col)
+			{
+				XmlSchemaElement elem = ob as XmlSchemaElement;
+				if (elem != null && elem.Name == name) return elem;
+			}
+			return null;
+		}
 
 		XmlSchemaAttribute GetSchemaAttribute (XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo)
 		{

+ 16 - 2
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs

@@ -33,6 +33,8 @@ namespace System.Xml.Serialization {
 		static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array",XmlSerializer.EncodingNamespace);
 		static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType",XmlSerializer.EncodingNamespace);
 		
+		const string XmlNamespace = "http://www.w3.org/XML/1998/namespace";
+		
 		XmlSchemaElement anyElement = null;
 
 		class MapFixup
@@ -1230,7 +1232,7 @@ namespace System.Xml.Serialization {
 			if (!attr.RefName.IsEmpty)
 			{
 				ns = attr.RefName.Namespace;
-				return (XmlSchemaAttribute) schemas.Find (attr.RefName, typeof(XmlSchemaAttribute));
+				return FindRefAttribute (attr.RefName);
 			}
 			else
 			{
@@ -1262,7 +1264,7 @@ namespace System.Xml.Serialization {
 			bool sharedAnnType = false;
 
 			if (!attr.RefName.IsEmpty) {
-				XmlSchemaAttribute refAtt = (XmlSchemaAttribute)schemas.Find (attr.RefName, typeof (XmlSchemaAttribute));
+				XmlSchemaAttribute refAtt = FindRefAttribute (attr.RefName);
 				if (refAtt == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
 				attr = refAtt;
 				sharedAnnType = true;
@@ -1363,6 +1365,18 @@ namespace System.Xml.Serialization {
 			}
 			return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
 		}
+		
+		XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
+		{
+			if (refName.Namespace == XmlNamespace)
+			{
+				XmlSchemaAttribute at = new XmlSchemaAttribute ();
+				at.Name = refName.Name;
+				at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
+				return at;
+			}
+			return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
+		}
 
 		string GetDocumentation (XmlSchemaAnnotated elem)
 		{

+ 2 - 0
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs

@@ -446,6 +446,8 @@ namespace System.Xml.Serialization {
 		bool ReadList (out object resultList)
 		{
 			string arrayType = Reader.GetAttribute ("arrayType", XmlSerializer.EncodingNamespace);
+			if (arrayType == null) arrayType = Reader.GetAttribute ("arrayType", XmlSerializer.WsdlNamespace);
+			
 			XmlQualifiedName qn = ToXmlQualifiedName (arrayType);
 			int i = qn.Name.LastIndexOf ('[');
 			string dim = qn.Name.Substring (i);

+ 1 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs

@@ -359,7 +359,7 @@ namespace System.Xml.Serialization
 				int itemCount = GetListCount (typeMap.TypeData, ob);
 				((ListMap) typeMap.ObjectMap).GetArrayType (itemCount, out n, out ns);
 				string arrayType = (ns != string.Empty) ? FromXmlQualifiedName (new XmlQualifiedName(n,ns)) : n;
-				WriteAttribute ("arrayType", XmlSerializer.WsdlNamespace, arrayType);
+				WriteAttribute ("arrayType", XmlSerializer.EncodingNamespace, arrayType);
 			}
 			WriteListContent (typeMap.TypeData, (ListMap) typeMap.ObjectMap, ob, null);
 		}