Author: atsushi
Date: 2005-03-03 04:25:16 -0500 (Thu, 03 Mar 2005)
New Revision: 41387

Modified:
   trunk/mcs/class/System.XML/System.Xml/ChangeLog
   trunk/mcs/class/System.XML/System.Xml/XmlTextWriter.cs
   trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
   trunk/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs
Log:
2005-03-03  Atsushi Enomoto <[EMAIL PROTECTED]>

        * XmlTextWriter.cs : For duplicating namespace mapping, it should
          create another prefix without throwing an exception.

        * XmlTextWriterTests.cs : added testcase for duplicating namespace 
          mapping processing (should create another prefix, not exception).



Modified: trunk/mcs/class/System.XML/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/ChangeLog     2005-03-03 08:41:58 UTC 
(rev 41386)
+++ trunk/mcs/class/System.XML/System.Xml/ChangeLog     2005-03-03 09:25:16 UTC 
(rev 41387)
@@ -1,3 +1,8 @@
+2005-03-03  Atsushi Enomoto <[EMAIL PROTECTED]>
+
+       * XmlTextWriter.cs : For duplicating namespace mapping, it should
+         create another prefix without throwing an exception.
+
 2005-03-02  Atsushi Enomoto <[EMAIL PROTECTED]>
 
        * XmlTextWriter.cs : LookupPrefix() should not return those prefix

Modified: trunk/mcs/class/System.XML/System.Xml/XmlTextWriter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml/XmlTextWriter.cs      2005-03-03 
08:41:58 UTC (rev 41386)
+++ trunk/mcs/class/System.XML/System.Xml/XmlTextWriter.cs      2005-03-03 
09:25:16 UTC (rev 41387)
@@ -73,6 +73,7 @@
                Hashtable newAttributeNamespaces = new Hashtable ();
                Hashtable userWrittenNamespaces = new Hashtable ();
                StringBuilder cachedStringBuilder;
+               int autoCreatedPrefixes;
 
                XmlNamespaceManager namespaceManager = new XmlNamespaceManager 
(new NameTable ());
                string savingAttributeValue = String.Empty;
@@ -328,16 +329,18 @@
 
                                        if (namespaceManager.LookupNamespace 
(aprefix, false) == ans)
                                                continue;
-       
+                                       ans = EscapeString (ans, false);
                                        w.Write (" xmlns:");
                                        w.Write (aprefix);
                                        w.Write ('=');
                                        w.Write (quoteChar);
-                                       w.Write (EscapeString (ans, false));
+                                       w.Write (ans);
                                        w.Write (quoteChar);
+                                       namespaceManager.AddNamespace (aprefix, 
ans);
                                }
                                newAttributeNamespaces.Clear ();
                        }
+                       autoCreatedPrefixes = 0;
                }
 
                private void CheckState ()
@@ -784,14 +787,18 @@
                                                        }
                                                }
                                        }
+
+                       do {
                                        if (createPrefix)
-                                               prefix = "d" + indentLevel + 
"p" + (newAttributeNamespaces.Count + 1);
-                                       
+                                               prefix = "d" + indentLevel + 
"p" + (++autoCreatedPrefixes);
+                                       createPrefix = false;
                                        // check if prefix exists. If yes - 
check if namespace is the same.
                                        if (newAttributeNamespaces [prefix] == 
null)
                                                newAttributeNamespaces.Add 
(prefix, ns);
                                        else if (!newAttributeNamespaces 
[prefix].Equals (ns))
-                                               throw new ArgumentException 
("Duplicate prefix with different namespace");
+//                                             throw new ArgumentException 
("Duplicate prefix with different namespace");
+                                               createPrefix = true;
+                       } while (createPrefix);
                                }
 
                                if (prefix == String.Empty && ns != 
XmlnsNamespace)

Modified: trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-03-03 
08:41:58 UTC (rev 41386)
+++ trunk/mcs/class/System.XML/Test/System.Xml/ChangeLog        2005-03-03 
09:25:16 UTC (rev 41387)
@@ -1,3 +1,8 @@
+2005-03-03  Atsushi Enomoto <[EMAIL PROTECTED]>
+
+       * XmlTextWriterTests.cs : added testcase for duplicating namespace 
+         mapping processing (should create another prefix, not exception).
+
 2005-03-02  Atsushi Enomoto <[EMAIL PROTECTED]>
 
        * XmlTextWriterTests.cs : Added test for LookupPrefix() for

Modified: trunk/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs    
2005-03-03 08:41:58 UTC (rev 41386)
+++ trunk/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs    
2005-03-03 09:25:16 UTC (rev 41387)
@@ -1317,5 +1317,29 @@
                        xtw.WriteStartElement ("baz", "foo", "abc");
                        AssertNull (xtw.LookupPrefix ("xyz"));
                }
+
+               [Test]
+               public void DuplicatingNamespaceMappingInAttributes ()
+               {
+                       xtw.WriteStartElement ("out");
+                       xtw.WriteAttributeString ("p", "foo", "urn:foo", "xyz");
+                       xtw.WriteAttributeString ("p", "bar", "urn:bar", "xyz");
+                       xtw.WriteAttributeString ("p", "baz", "urn:baz", "xyz");
+                       xtw.WriteStartElement ("out");
+                       xtw.WriteAttributeString ("p", "foo", "urn:foo", "xyz");
+                       xtw.WriteStartElement ("out");
+                       xtw.WriteAttributeString ("p", "foo", "urn:foo", "xyz");
+                       xtw.WriteEndElement ();
+                       xtw.WriteEndElement ();
+                       xtw.WriteEndElement ();
+                       string xml = sw.ToString ();
+                       Assert ("p:foo", xml.IndexOf ("p:foo='xyz'") > 0);
+                       Assert ("d1p1:bar", xml.IndexOf ("d1p1:bar='xyz'") > 0);
+                       Assert ("d1p1:baz", xml.IndexOf ("d1p2:baz='xyz'") > 0);
+                       Assert ("xmlns:d1p2", xml.IndexOf 
("xmlns:d1p2='urn:baz'") > 0);
+                       Assert ("xmlns:d1p1", xml.IndexOf 
("xmlns:d1p1='urn:bar'") > 0);
+                       Assert ("xmlns:p", xml.IndexOf ("xmlns:p='urn:foo'") > 
0);
+                       Assert ("remaining", xml.IndexOf ("<out 
p:foo='xyz'><out p:foo='xyz' /></out></out>") > 0);
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to