/// <summary>
 ///     Initializes a new instance of the DynaXmlContextState class.
 /// </summary>
 /// <param name="document">The xml document.</param>
 /// <param name="currentAncestor">The current ancestor of all new nodes.</param>
 /// <param name="lastCreated">The last node that was created.</param>
 /// <param name="namespaceContext">The current namespace context.</param>
 /// <param name="state">The current state of the state machine.</param>
 public DynaXmlContextState(DynaXmlDocument document,
                            DynaXmlElement currentAncestor,
                            DynaXmlElement lastCreated,
                            DynaXmlNamespaceContext namespaceContext,
                            DynaXmlBuilderState state)
 {
     this.Document = document;
     this.State = state;
     this.CurentAncestorElement = currentAncestor;
     this.CurrentNamespaceContext = namespaceContext;
     this.LastCreated = lastCreated;
 }
 /// <summary>
 ///     Pushes a new state into the stack (thus changing the current state to the new state).
 ///     This method allows for both a new node and a new state to be supplied.
 /// </summary>
 /// <param name="newAncestor">
 ///     The new XmlNode representing the ancestor for all new nodes.
 /// </param>
 /// <param name="state">
 ///     The new state.
 /// </param>
 internal void Push(DynaXmlElement newAncestor, DynaXmlBuilderState state)
 {
     this.stack.Push(new DynaXmlContextState(this.Document,
                                             newAncestor,
                                             newAncestor,
                                             new DynaXmlNamespaceContext(this.CurrentNamespaceContext),
                                             state));
 }
 /// <summary>
 /// Creates a new element in the XmlDocument.
 /// </summary>
 /// <param name="name">
 /// The name of the element.
 /// </param>
 /// <returns>
 /// The XmlElement that was created.
 /// </returns>
 private DynaXmlElement CreateElement(string name)
 {
     DynaXmlElement element = null;
     var currentAlias = this.CurrentNamespaceContext.CurrentAlias;
     if (currentAlias.IsNotNullOrEmpty())
     {
         element = new DynaXmlElement()
         {
             Prefix = currentAlias,
             LocalName = name,
             XmlNamespace = this.CurrentNamespaceContext.AliasTable[currentAlias]
         };
         // We've used the "CurrentAlias" so remove it as it's a (use once state);
         this.CurrentNamespaceContext.CurrentAlias = string.Empty;
         this.CurrentNamespaceContext.ApplyCurrentToAttributes = false;
     }
     else if (this.CurrentNamespaceContext.DefaultNamespace.IsNullOrEmpty())
     {
         element = new DynaXmlElement() { LocalName = name };
     }
     else
     {
         element = new DynaXmlElement() { LocalName = name, XmlNamespace = this.CurrentNamespaceContext.DefaultNamespace };
     }
     if (this.CurrentAncestorElement.IsNull())
     {
         element.Items.AddRange(this.rootNodeNamespaceDefinitions);
     }
     return element;
 }
 /// <summary>
 ///     Pushes a new state into the stack (thus changing the current state to the new state).
 /// </summary>
 /// <param name="element">
 ///     The XmlELement representing the current state.
 /// </param>
 public void PushElement(DynaXmlElement element)
 {
     this.CurrentAncestorNode.Items.Add(element);
     this.Push(element, DynaXmlBuilderState.ElementListBuilder);
 }