return prefix;
}
- static string CreateDummyNamespace (ref int createdNS, IEnumerable<XAttribute> atts)
+ static string CreateDummyNamespace (ref int createdNS, IEnumerable<XAttribute> atts, bool isAttr)
{
+ if (!isAttr && atts.All (a => a.Name.LocalName != "xmlns" || a.Name.NamespaceName == XNamespace.Xmlns.NamespaceName))
+ return String.Empty;
string p = null;
do {
p = "p" + (++createdNS);
// check conflict
- if (atts.All (a => a.Name.LocalName != p))
+ if (atts.All (a => a.Name.LocalName != p || a.Name.NamespaceName == XNamespace.Xmlns.NamespaceName))
break;
} while (true);
return p;
string prefix = LookupPrefix (name.NamespaceName, w);
int createdNS = 0;
if (prefix == null)
- prefix = CreateDummyNamespace (ref createdNS, Attributes ());
+ prefix = CreateDummyNamespace (ref createdNS, Attributes (), false);
w.WriteStartElement (prefix, name.LocalName, name.Namespace.NamespaceName);
} else {
string apfix = LookupPrefix (a.Name.NamespaceName, w);
if (apfix == null)
- apfix = CreateDummyNamespace (ref createdNS, Attributes ());
+ apfix = CreateDummyNamespace (ref createdNS, Attributes (), true);
w.WriteAttributeString (apfix, a.Name.LocalName, a.Name.Namespace.NamespaceName, a.Value);
}
}
string expected = @"<xsi:eventData xsi1:type='xsi:CallSubscriptionEvent' xmlns:xsi1='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsi='http://relevo.se/xsi' />".Replace ('\'', '"');
Assert.AreEqual (expected, e.Nodes ().First ().ToString (), "#1");
}
+
+ [Test] // bug #5519
+ public void DoUseEmptyNamespacePrefixWhenApplicable ()
+ {
+ XNamespace ns = "http://jabber.org/protocol/geoloc";
+ XElement newElement = new XElement(ns + "geoloc");
+ Assert.AreEqual ("<geoloc xmlns=\"http://jabber.org/protocol/geoloc\" />", newElement.ToString (), "#1");
+ }
}
}