XmlNode parent;
XmlNode current;
XmlNode nextSibling;
- Stack nodeStack = new Stack ();
+ WriteState state;
+ XmlAttribute attribute;
public XmlDocumentInsertionWriter (XmlNode owner, XmlNode nextSibling)
{
state = WriteState.Content;
}
- WriteState state;
- XmlAttribute attribute;
-
public override WriteState WriteState {
get { return state; }
}
public override void Close ()
{
- while (nodeStack.Count > 0) {
- XmlNode n = nodeStack.Pop () as XmlNode;
- n.AppendChild (current);
- current = n;
- }
+ while (current.ParentNode != null)
+ current = current.ParentNode;
+
parent.InsertBefore ((XmlDocumentFragment) current, nextSibling);
if (Closed != null)
Closed (this);
internal event XmlWriterClosedEventHandler Closed;
- internal XmlNode AppendedFirstChild;
-
public override void Flush ()
{
}
{
if (state != WriteState.Content)
throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
attribute = current.OwnerDocument.CreateAttribute (prefix, name, ns);
state = WriteState.Attribute;
}
public override void WriteStartElement (string prefix, string name, string ns)
{
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
XmlElement el = current.OwnerDocument.CreateElement (prefix, name, ns);
current.AppendChild (el);
- nodeStack.Push (current);
current = el;
}
public override void WriteEndElement ()
{
- if (nodeStack.Count == 0)
+ current = current.ParentNode;
+ if (current == null)
throw new InvalidOperationException ("No element is opened.");
- current = nodeStack.Pop () as XmlNode;
}
public override void WriteFullEndElement ()
internal class XmlDocumentAttributeWriter : XmlWriter
{
XmlElement element;
+ WriteState state;
+ XmlAttribute attribute;
public XmlDocumentAttributeWriter (XmlNode owner)
{
state = WriteState.Content;
}
- WriteState state;
- XmlAttribute attribute;
-
public override WriteState WriteState {
get { return state; }
}
{
if (state != WriteState.Content)
throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
attribute = element.OwnerDocument.CreateAttribute (prefix, name, ns);
state = WriteState.Attribute;
}