Ejemplo n.º 1
0
        /// <summary>
        /// Creates an Xml Attribute.
        /// </summary>
        /// <param name="name">
        /// The name of the attribute.
        /// </param>
        /// <param name="value">
        /// The value of the attribute.
        /// </param>
        /// <returns>
        /// The new attribute.
        /// </returns>
        private DynaXmlAttribute CreateAttribute(string name, string value)
        {
            DynaXmlAttribute retval;
            var currentAlias = this.CurrentNamespaceContext.CurrentAlias;

            if (!this.CurrentNamespaceContext.ApplyCurrentToAttributes)
            {
                retval = new DynaXmlAttribute()
                {
                    LocalName = name
                };
            }
            else
            {
                retval = new DynaXmlAttribute()
                {
                    Prefix       = currentAlias,
                    LocalName    = name,
                    XmlNamespace = this.CurrentNamespaceContext.AliasTable[currentAlias]
                };
                // We've used the current alias so remove it as it is a (use once state)
                this.CurrentNamespaceContext.CurrentAlias             = string.Empty;
                this.CurrentNamespaceContext.ApplyCurrentToAttributes = false;
            }
            retval.Value = value;
            return(retval);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new XmlNamespace element.
        /// </summary>
        /// <param name="prefix">The prefix for the namespace.</param>
        /// <param name="xmlNamespace">The namespace.</param>
        /// <returns>A new XmlAttribute representing the namespace.</returns>
        private DynaXmlAttribute CreateNamespace(string prefix, string xmlNamespace)
        {
            DynaXmlAttribute namespaceDefinition = new DynaXmlAttribute()
            {
                Prefix       = "xmlns",
                LocalName    = prefix,
                XmlNamespace = Xmlns
            };

            this.CurrentNamespaceContext.AliasTable.Add(prefix, xmlNamespace);
            namespaceDefinition.Value = xmlNamespace;
            return(namespaceDefinition);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Changes the current namespace alias for the current context.
        /// </summary>
        /// <param name="name">
        /// The alias for the new namespace.
        /// </param>
        /// <param name="xmlNamespace">
        /// The namespace Url to apply.
        /// </param>
        /// <returns>
        /// Always true.
        /// </returns>
        private bool NamespaceBuilderInvokeMember(string name, string xmlNamespace)
        {
            // First check to make sure the namespace has not already been defined
            // on this element.  It's okay if it's in the current context, but it
            // cant be on the AncestorElement.
            ICollection <DynaXmlAttribute> currentAttributes;

            if (this.CurrentAncestorElement.IsNotNull())
            {
                currentAttributes = new List <DynaXmlAttribute>();
                foreach (DynaXmlAttribute attrib in this.CurrentAncestorElement.Attributes)
                {
                    currentAttributes.Add(attrib);
                }
            }
            else
            {
                currentAttributes = this.rootNodeNamespaceDefinitions;
            }

            DynaXmlAttribute attribute = (from a in currentAttributes
                                          where a.LocalName == name &&
                                          a.XmlNamespace == Xmlns
                                          select a).FirstOrDefault();

            if (attribute.IsNotNull())
            {
                attribute.Value = xmlNamespace;
            }
            else
            {
                attribute = this.CreateNamespace(name, xmlNamespace);
                if (this.CurrentAncestorElement.IsNotNull())
                {
                    this.CurrentAncestorElement.Items.Add(attribute);
                }
                else
                {
                    this.rootNodeNamespaceDefinitions.Add(attribute);
                }
            }

            // Again we pop the context first.
            this.context.Pop();
            // Then we make the changes in the Namespace area of the context.
            this.CurrentNamespaceContext.AliasTable[name] = xmlNamespace;
            return(true);
        }