From 2e0e15d706b7898ce03aa7334f50a4da982d32a4 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 5 Oct 2010 00:05:37 +0900 Subject: [PATCH] Adjust namespace prefix indexes as it is repeatedly used. (It could result in duplicate prefix.) --- .../System.Xml/XmlDictionaryWriter.cs | 17 +++++++++-------- .../System.Xml/XmlSimpleDictionaryWriter.cs | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs b/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs index d73ccffcaa6..eb126942fab 100644 --- a/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs +++ b/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs @@ -36,16 +36,13 @@ namespace System.Xml { static readonly Encoding utf8_unmarked = new UTF8Encoding (false); - int depth; - protected XmlDictionaryWriter () { } - internal int Depth { - get { return depth; } - set { depth = value; } - } + internal int Depth { get; set; } + + internal int NSIndex { get; set; } public virtual bool CanCanonicalize { get { return false; } @@ -138,6 +135,8 @@ namespace System.Xml return CreateDictionaryWriter (XmlWriter.Create (stream, s)); } + + public virtual void EndCanonicalization () { throw new NotSupportedException (); @@ -388,8 +387,10 @@ namespace System.Xml // writer how it is determined in the output. (When // there is a duplicate, then it will be further // modified.) - if (prefix == null) - prefix = "d" + Depth + "p1"; + if (prefix == null && String.IsNullOrEmpty (namespaceUri)) + prefix = String.Empty; + else if (prefix == null) + prefix = "d" + Depth + "p" + (++NSIndex); if (prefix == String.Empty) WriteAttributeString ("xmlns", namespaceUri); diff --git a/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs b/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs index 9eb5d3aa06b..2afb6bc9cbb 100644 --- a/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs +++ b/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs @@ -105,6 +105,7 @@ namespace System.Xml public override void WriteEndElement () { Depth--; + NSIndex = 0; writer.WriteEndElement (); } @@ -171,6 +172,7 @@ namespace System.Xml public override void WriteStartElement (string prefix, string localName, string ns) { Depth++; + NSIndex = 0; writer.WriteStartElement (prefix, localName, ns); } -- GitLab