2002-08-22 Tim Coleman <tim@timcoleman.com>
authorTim Coleman <tim@mono-cvs.ximian.com>
Thu, 22 Aug 2002 15:57:12 +0000 (15:57 -0000)
committerTim Coleman <tim@mono-cvs.ximian.com>
Thu, 22 Aug 2002 15:57:12 +0000 (15:57 -0000)
        * XmlSerializationWriter.cs:
                More implementation
        * XmlCustomFormatter.sc:
                Implemented this class.

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

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs [new file with mode: 0644]
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs

index 24cf8b131371c18b45b468c08459a1c04dab3d7f..d441afe29d95a2a62ee5cd8a2dff79c1e47ccbfa 100755 (executable)
@@ -1,3 +1,9 @@
+2002-08-22  Tim Coleman <tim@timcoleman.com>
+       * XmlSerializationWriter.cs:
+               More implementation
+       * XmlCustomFormatter.sc:
+               Implemented this class.
+
 2002-08-20  Tim Coleman <tim@timcoleman.com>
        * XmlSerializationWriter.cs:
                Some implementation.
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs
new file mode 100644 (file)
index 0000000..6820772
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// System.Xml.Serialization.XmlCustomFormatter.cs
+//
+// Author:
+//   Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System;
+using System.Text;
+using System.Xml;
+
+namespace System.Xml.Serialization {
+       internal class XmlCustomFormatter {
+
+               #region Methods
+
+               public static string FromXmlName (string name)
+               {
+                       return XmlConvert.EncodeName (name);
+               }
+
+               public static string FromXmlNCName (string ncName)
+               {
+                       return XmlConvert.EncodeLocalName (ncName);
+               }
+
+               public static string FromXmlNmToken (string nmToken)
+               {
+                       return XmlConvert.EncodeNmToken (nmToken);
+               }
+
+               public static string FromXmlNmTokens (string nmTokens)
+               {
+                       StringBuilder output = new StringBuilder ();
+                       string [] tokens = nmTokens.Split (' ');
+                       foreach (string token in tokens)
+                               output.Append (FromXmlNmToken (token));
+                       return output.ToString ();
+               }
+
+               #endregion // Methods
+       }
+}
index 040b399f5ea2c9c80d12279d9b280856377b714d..ec4461f56b4d8059c4e72b0a5c5f088a671c9bc1 100644 (file)
@@ -10,6 +10,7 @@
 using System;
 using System.Collections;
 using System.Xml;
+using System.Xml.Schema;
 
 namespace System.Xml.Serialization {
        public abstract class XmlSerializationWriter {
@@ -26,7 +27,6 @@ namespace System.Xml.Serialization {
                [MonoTODO]
                protected XmlSerializationWriter ()
                {
-                       throw new NotImplementedException ();
                }
 
                #endregion // Constructors
@@ -120,31 +120,37 @@ namespace System.Xml.Serialization {
                [MonoTODO ("Implement")]
                protected static string FromXmlName (string name)
                {
-                       throw new NotImplementedException ();
+                       return XmlCustomFormatter.FromXmlName (name);
                }
 
                [MonoTODO ("Implement")]
                protected static string FromXmlNCName (string ncName)
                {
-                       throw new NotImplementedException ();
+                       return XmlCustomFormatter.FromXmlNCName (ncName);
                }
 
                [MonoTODO ("Implement")]
                protected static string FromXmlNmToken (string nmToken)
                {
-                       throw new NotImplementedException ();
+                       return XmlCustomFormatter.FromXmlNmToken (nmToken);
                }
 
                [MonoTODO ("Implement")]
                protected static string FromXmlNmTokens (string nmTokens)
                {
-                       throw new NotImplementedException ();
+                       return XmlCustomFormatter.FromXmlNmTokens (nmTokens);
                }
 
                [MonoTODO ("Implement")]
                protected string FromXmlQualifiedName (XmlQualifiedName xmlQualifiedName)
                {
-                       throw new NotImplementedException ();
+                       return GetQualifiedName (xmlQualifiedName.Name, xmlQualifiedName.Namespace).ToString ();
+               }
+
+               private XmlQualifiedName GetQualifiedName (string name, string ns)
+               {
+                       WriteAttribute ("xmlns", "q1", null, ns);
+                       return new XmlQualifiedName (name, "q1");
                }
 
                protected abstract void InitCallbacks ();
@@ -176,10 +182,9 @@ namespace System.Xml.Serialization {
                        WriteAttribute (String.Empty, localName, ns, value);
                }
 
-               [MonoTODO ("Implement")]
                protected void WriteAttribute (string prefix, string localName, string ns, string value)
                {
-                       throw new NotImplementedException ();
+                       Writer.WriteAttributeString (prefix, localName, ns, value);
                }
 
                [MonoTODO ("Implement")]
@@ -191,31 +196,31 @@ namespace System.Xml.Serialization {
                [MonoTODO ("Implement")]
                protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any)
                {
-                       throw new NotImplementedException ();
+                       WriteStartElement (name, ns);
+                       node.WriteTo (Writer);
+                       WriteEndElement ();
                }
 
-               [MonoTODO ("Implement")]
                protected void WriteElementQualifiedName (string localName, XmlQualifiedName value)
                {
-                       throw new NotImplementedException ();
+                       WriteElementQualifiedName (localName, String.Empty, value, null);
                }
 
-               [MonoTODO ("Implement")]
                protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value)
                {
-                       throw new NotImplementedException ();
+                       WriteElementQualifiedName (localName, ns, value, null);
                }
 
-               [MonoTODO ("Implement")]
                protected void WriteElementQualifiedName (string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
                {
-                       throw new NotImplementedException ();
+                       WriteElementQualifiedName (localName, String.Empty, value, xsiType);
                }
 
-               [MonoTODO ("Implement")]
                protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
                {
-                       throw new NotImplementedException ();
+                       WriteStartElement (localName, ns);
+                       Writer.WriteString (FromXmlQualifiedName (value));
+                       WriteEndElement ();
                }
 
                protected void WriteElementString (string localName, string value)
@@ -236,7 +241,13 @@ namespace System.Xml.Serialization {
                [MonoTODO ("Implement")]
                protected void WriteElementString (string localName, string ns, string value, XmlQualifiedName xsiType)
                {
-                       throw new NotImplementedException ();
+                       WriteStartElement (localName, ns);
+
+                       if (xsiType != null)
+                               WriteXsiType (xsiType.Name, xsiType.Namespace);
+
+                       Writer.WriteString (value);
+                       WriteEndElement ();
                }
 
                protected void WriteElementStringRaw (string localName, byte[] value)
@@ -278,7 +289,13 @@ namespace System.Xml.Serialization {
                [MonoTODO ("Implement")]
                protected void WriteElementStringRaw (string localName, string ns, string value, XmlQualifiedName xsiType)
                {
-                       throw new NotImplementedException ();
+                       WriteStartElement (localName, ns);
+
+                       if (xsiType != null)
+                               WriteXsiType (xsiType.Name, xsiType.Namespace);
+
+                       Writer.WriteRaw (value);
+                       WriteEndElement ();
                }
 
                protected void WriteEmptyTag (string name)
@@ -286,10 +303,11 @@ namespace System.Xml.Serialization {
                        WriteEmptyTag (name, String.Empty);
                }
 
-               [MonoTODO ("Implement")]
+               [MonoTODO ("Verify")]
                protected void WriteEmptyTag (string name, string ns)
                {
-                       throw new NotImplementedException ();
+                       Writer.WriteStartElement (name, ns);
+                       Writer.WriteEndElement ();
                }
 
                protected void WriteEndElement ()
@@ -300,7 +318,7 @@ namespace System.Xml.Serialization {
                [MonoTODO ("Implement")]
                protected void WriteEndElement (object o)
                {
-                       throw new NotImplementedException ();
+                       Writer.WriteEndElement ();
                }
 
                [MonoTODO ("Implement")]
@@ -448,16 +466,25 @@ namespace System.Xml.Serialization {
                        WriteStartElement (name, ns, o, false);
                }
 
-               [MonoTODO ("Implement")]
+               [MonoTODO]
                protected void WriteStartElement (string name, string ns, object o, bool writePrefixed)
                {
-                       throw new NotImplementedException ();
+                       if (writePrefixed)
+                               Writer.WriteStartElement (String.Empty, name, ns);
+                       else
+                               Writer.WriteStartElement (name, ns);
                }
 
-               [MonoTODO ("Implement")]
+               [MonoTODO ("Include XMLSchema-Instance namespace")]
                protected void WriteTypedPrimitive (string name, string ns, object o, bool xsiType)
                {
-                       throw new NotImplementedException ();
+                       if (!xsiType) {
+                               WriteElementString (name, ns, o.ToString ());
+                               return;
+                       }
+
+                       XmlQualifiedName xsiTypeQName = new XmlQualifiedName (o.GetType ().Name, XmlSchema.Namespace);
+                       WriteElementString (name, ns, o.ToString (), xsiTypeQName);
                }
 
                protected void WriteValue (byte[] value)
@@ -482,11 +509,12 @@ namespace System.Xml.Serialization {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO ("Implement")]
+               [MonoTODO ("Change prefix")]
                protected void WriteXsiType (string name, string ns)
                {
-                       throw new NotImplementedException ();
+                       WriteAttribute ("d0p1", "type", null, GetQualifiedName (name, ns).ToString ());
                }
+               
 
 
                #endregion