Exemple #1
0
        private bool IsAtomDefaultNamespace(XmlWriter writer)
        {
            string prefix = writer.LookupPrefix(BaseNameTable.NSAtom);

            if (prefix == null)
            {
                // if it is not defined, we need to make a choice
                // go over all attributes
                foreach (IExtensionElementFactory ele in this.ExtensionElements)
                {
                    XmlExtension x = ele as XmlExtension;
                    // what we need to do here is:
                    // go over all the attributes. look at all attributes that are namespace related
                    // if the attribute is another default atomnamespace declaration, change it to some rnd prefix

                    if (x != null)
                    {
                        if (x.Node.NodeType == XmlNodeType.Attribute &&
                            (String.Compare(x.Node.Name, "xmlns") == 0) &&
                            (String.Compare(x.Node.Value, BaseNameTable.NSAtom) != 0))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
            if (prefix.Length > 0)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        /// <summary>protected virtual int SaveXmlAttributes(XmlWriter writer)</summary>
        /// <param name="writer">the XmlWriter to save to</param>
        protected virtual void SaveXmlAttributes(XmlWriter writer)
        {
            Tracing.Assert(writer != null, "writer should not be null");
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            // this will save the base and language attributes, if we have them
            if (Utilities.IsPersistable(this.uriBase))
            {
                //Lookup the prefix and then write the ISBN attribute.
                writer.WriteAttributeString("xml", "base", BaseNameTable.NSXml, this.Base.ToString());
            }

            if (Utilities.IsPersistable(this.atomLanguageTag))
            {
                writer.WriteAttributeString("xml", "lang", BaseNameTable.NSXml, this.Language);
            }

            ISupportsEtag se = this as ISupportsEtag;

            if (se != null && se.Etag != null)
            {
                writer.WriteAttributeString(BaseNameTable.gDataPrefix, BaseNameTable.XmlEtagAttribute, BaseNameTable.gNamespace, se.Etag);
            }

            // first go over all attributes
            foreach (IExtensionElementFactory ele in this.ExtensionElements)
            {
                XmlExtension x = ele as XmlExtension;
                // what we need to do here is:
                // go over all the attributes. look at all attributes that are namespace related
                // if the attribute is another default atomnamespace declaration, change it to some rnd prefix

                if (x != null)
                {
                    if (x.Node.NodeType == XmlNodeType.Attribute)
                    {
                        ele.Save(writer);
                    }
                }
            }
            AddOtherNamespaces(writer);

            // now just the non attributes
            foreach (IExtensionElementFactory ele in this.ExtensionElements)
            {
                XmlExtension x = ele as XmlExtension;
                if (x != null)
                {
                    if (x.Node.NodeType == XmlNodeType.Attribute)
                    {
                        // skip the guy
                        continue;
                    }
                }
                ele.Save(writer);
            }
        }