Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Henrich <marcos.henrich@xamarin.com>2014-12-12 22:07:33 +0300
committerMarcos Henrich <marcos.henrich@xamarin.com>2014-12-12 22:50:15 +0300
commitaad3c917e41f4dc319117a6c42d12b34d8e5bdaf (patch)
tree667e591d831d1e40a82aa4514697e5da0ab80986 /mcs/class/System.Xml.Linq
parent2039c7d499cf113016a6feba4f3596072a33e843 (diff)
[System.Xml.Linq] xmlns prefixes are no longer generated in some cases.
- XNodeWrite.FillXmlns was adding a prefix to the attribute when no prefix was found (prefix==null) - XNodeWrite.LookupPrefix now returns string.Empty prefix when the namespace is the same as the element. A string.Empty prefix explicitly states that it has no prefix whereas null states that prefix was not defined. When LookupPrefix returns null for a namespace it means that a prefix should be generated first for anything that uses the namespace. That is what XmlSerializationWriter.GetQualifiedName does. Fixes #24300
Diffstat (limited to 'mcs/class/System.Xml.Linq')
-rw-r--r--mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs b/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs
index 3ba281f187a..54c62516cf1 100644
--- a/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs
+++ b/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeWriter.cs
@@ -139,10 +139,11 @@ namespace System.Xml.Linq
if (prefix == null)
return;
- if (xns == XNamespace.None)
- if (el.GetPrefixOfNamespace (xns) != prefix)
+ if (xns == XNamespace.None) {
+ var xnsPrefix = el.GetPrefixOfNamespace (xns);
+ if (xnsPrefix != null && xnsPrefix != prefix)
el.SetAttributeValue (prefix == String.Empty ? XNamespace.None.GetName ("xmlns") : XNamespace.Xmlns.GetName (prefix), xns.NamespaceName);
- else if (el.GetDefaultNamespace () != XNamespace.None)
+ } else if (el.GetDefaultNamespace () != XNamespace.None)
el.SetAttributeValue (XNamespace.None.GetName ("xmlns"), xns.NamespaceName);
}
@@ -164,6 +165,10 @@ namespace System.Xml.Linq
if (current == null)
throw new InvalidOperationException ();
XElement el = (current as XElement) ?? current.Parent;
+
+ if (ns == el.Name.Namespace.NamespaceName)
+ return "";
+
return el != null ? el.GetPrefixOfNamespace (XNamespace.Get (ns)) : null;
}