+ OnAddedObject (a);
+ }
+
+ string LookupPrefix (string ns, XmlWriter w)
+ {
+ string prefix = ns.Length > 0 ? GetPrefixOfNamespace (ns) ?? w.LookupPrefix (ns) : String.Empty;
+ foreach (XAttribute a in Attributes ()) {
+ if (a.IsNamespaceDeclaration && a.Value == ns) {
+ if (a.Name.Namespace == XNamespace.Xmlns)
+ prefix = a.Name.LocalName;
+ // otherwise xmlns="..."
+ break;
+ }
+ }
+ return prefix;
+ }
+
+ 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 || a.Name.NamespaceName == XNamespace.Xmlns.NamespaceName))
+ break;
+ } while (true);
+ return p;