2003-06-16 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 16 Jun 2003 17:15:55 +0000 (17:15 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 16 Jun 2003 17:15:55 +0000 (17:15 -0000)
* XmlSerializationReader.cs : Synchronous fix with
  XmlElement.GetAttribute(name, ns) fix for GetNullAttr().
* added XmlTypeMapMemberNamespace.cs.
* XmlReflectionImporter,
  XmlSerializationReaderInterpreter.cs,
  XmlSerializationWriterInterpreter.cs,
  XmlTypeMapping.cs : support for XmlNamespaceDeclarationAttribute.

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

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberNamespaces.cs [new file with mode: 0644]
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs

index c34df66c8c252f0901aecedf60343581d5d12ba1..053c6bafe4ee23b4f7358257319153516ba6e190 100755 (executable)
@@ -1,3 +1,13 @@
+2003-06-16  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * XmlSerializationReader.cs : Synchronous fix with 
+         XmlElement.GetAttribute(name, ns) fix for GetNullAttr().
+       * added XmlTypeMapMemberNamespace.cs.
+       * XmlReflectionImporter,
+         XmlSerializationReaderInterpreter.cs,
+         XmlSerializationWriterInterpreter.cs,
+         XmlTypeMapping.cs : support for XmlNamespaceDeclarationAttribute.
+
 2003-06-16  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * XmlSerializationWriter.cs : some QName handling fix.
index ebda7356d0884325deb3fd3f0a1c0a2fab482167..1ca5537d57274b30f2345c1fbc95bf604434f5ee 100644 (file)
@@ -179,18 +179,18 @@ namespace System.Xml.Serialization {
 
                        // Import members
 
-                       try
-                       {
+//                     try
+//                     {
                                ICollection members = GetReflectionMembers (type);
                                foreach (XmlReflectionMember rmember in members)
                                {
                                        if (rmember.XmlAttributes.XmlIgnore) continue;
                                        classMap.AddMember (CreateMapMember (rmember, map.Namespace));
                                }
-                       }
-                       catch (Exception ex) {
-                               throw helper.CreateError (map, ex.Message);
-                       }
+//                     }
+//                     catch (Exception ex) {
+//                             throw helper.CreateError (map, ex.Message);
+//                     }
 
                        // Import derived classes
 
@@ -437,6 +437,11 @@ namespace System.Xml.Serialization {
                                else
                                        throw new InvalidOperationException ("XmlAnyElementAttribute can only be applied to members of type XmlElement, XmlElement[] or XmlNode[]");
                        }
+                       else if (atts.Xmlns)
+                       {
+                               XmlTypeMapMemberNamespaces mapNamespaces = new XmlTypeMapMemberNamespaces ();
+                               mapMember = mapNamespaces;
+                       }
                        else if (atts.XmlAttribute != null)
                        {
                                // An attribute
index 20aa8e7fa8ea49e9e9898f4b56265a2e811a3be2..b4d67775d98e99915ba8cb6de33274f5a074b664 100644 (file)
@@ -252,15 +252,15 @@ namespace System.Xml.Serialization {
                protected bool GetNullAttr ()
                {
                        string na = reader.GetAttribute (nullX, w3InstanceNS);
-                       if (na == string.Empty) {
+                       if (na == null) {
                                na = reader.GetAttribute (nil, w3InstanceNS);
-                               if (na == string.Empty) {
+                               if (na == null) {
                                        na = reader.GetAttribute (nullX, w3InstanceNS2000);
-                                       if (na == string.Empty)
+                                       if (na == null)
                                                na = reader.GetAttribute (nullX, w3InstanceNS1999);
                                }
                        }
-                       return (na != string.Empty);
+                       return (na != null);
                }
 
                protected object GetTarget (string id)
index 83fee1a1ca1bfbecb0097e6fec08cad2eaa5b690..1cd5d2a222c05af5fd8aaf9c0fb60a98a847ae5f 100644 (file)
@@ -176,7 +176,20 @@ namespace System.Xml.Serialization
                                        }
                                        else if (IsXmlnsAttribute(Reader.Name)) 
                                        {
-                                               // Ignore
+                                               // If the map has NamespaceDeclarations,
+                                               // then store this xmlns to the given member.
+                                               // If the instance doesn't exist, then create.
+                                               if (map.NamespaceDeclarations != null) {
+                                                       XmlSerializerNamespaces nss = this.GetMemberValue (map.NamespaceDeclarations, ob, isValueList) as XmlSerializerNamespaces;
+                                                       if (nss == null) {
+                                                               nss = new XmlSerializerNamespaces ();
+                                                               SetMemberValue (map.NamespaceDeclarations, ob, nss, isValueList);
+                                                       }
+                                                       if (Reader.Prefix == "xmlns")
+nss.Add (Reader.LocalName, Reader.Value);
+                                                       else
+                                                               nss.Add ("", Reader.Value);
+                                               }
                                        }       
                                        else if (anyAttrMember != null) 
                                        {
index d32305c9bc966948f75b0c55b738fc2da591f75f..df06f8807f33a15bdfda0d2b7573546bf1f33104 100644 (file)
@@ -137,6 +137,8 @@ namespace System.Xml.Serialization
                void WriteObjectElement (XmlTypeMapping typeMap, object ob, string element, string namesp)
                {
                        ClassMap map = (ClassMap)typeMap.ObjectMap;
+                       if (map.NamespaceDeclarations != null)
+                               WriteNamespaceDeclarations ((XmlSerializerNamespaces) map.NamespaceDeclarations.GetValue (ob));
                        WriteMembers (map, ob, false);
                }
 
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberNamespaces.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberNamespaces.cs
new file mode 100644 (file)
index 0000000..b1e128d
--- /dev/null
@@ -0,0 +1,25 @@
+//
+// XmlTypeMapMemberNamespaces.cs: 
+//
+// Author:
+//   Atsushi Enomoto
+//
+// (C) 2003 Atsushi Enomoto
+//
+
+using System;
+using System.Xml.Schema;
+
+namespace System.Xml.Serialization
+{
+       // XmlTypeMapMemberNamespaces
+       // A member of a class that must be used to add namespace declarations.
+       // It must be limited at most 1 in a class.
+
+       internal class XmlTypeMapMemberNamespaces: XmlTypeMapMember
+       {
+               public XmlTypeMapMemberNamespaces()
+               {
+               }
+       }
+}
index 34604d00ae8ce7dc2c4cd47c93bc5e7d081ee4e8..e67b4791e3fc36caaa70bf48b1a3eaba42afcc18 100644 (file)
@@ -104,6 +104,7 @@ namespace System.Xml.Serialization
                ArrayList _flatLists;\r
                XmlTypeMapMemberAnyElement _defaultAnyElement;\r
                XmlTypeMapMemberAnyAttribute _defaultAnyAttribute;\r
+               XmlTypeMapMemberNamespaces _namespaceDeclarations;\r
                XmlTypeMapMember _xmlTextCollector;\r
 \r
                public void AddMember (XmlTypeMapMember member)\r
@@ -130,6 +131,11 @@ namespace System.Xml.Serialization
                                _defaultAnyAttribute = (XmlTypeMapMemberAnyAttribute) member;\r
                                return;\r
                        }\r
+                       else if (member is XmlTypeMapMemberNamespaces)\r
+                       {\r
+                               _namespaceDeclarations = (XmlTypeMapMemberNamespaces) member;\r
+                               return;\r
+                       }\r
 \r
                        if (member is XmlTypeMapMemberElement && ((XmlTypeMapMemberElement)member).IsXmlTextCollector)\r
                        {\r
@@ -184,6 +190,11 @@ namespace System.Xml.Serialization
                        get { return _defaultAnyAttribute; }\r
                }\r
 \r
+               public XmlTypeMapMemberNamespaces NamespaceDeclarations\r
+               {\r
+                       get { return _namespaceDeclarations; }\r
+               }\r
+\r
                public ICollection AttributeMembers\r
                {\r
                        get { return (_attributeMembers != null) ? _attributeMembers.Values : null; }\r