//
// (C)2003 Atsushi Enomoto
//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;
using System.Xml;
-namespace Mono.Xml
+namespace System.Xml
{
- public class XmlNodeWriter : XmlWriter
+ internal class XmlNodeWriter : XmlWriter
{
public XmlNodeWriter () : this (true)
{
}
// It should be public after some tests are done :-)
- private XmlNodeWriter (bool isDocumentEntity)
+ public XmlNodeWriter (bool isDocumentEntity)
{
doc = new XmlDocument ();
state = XmlNodeType.None;
this.isDocumentEntity = isDocumentEntity;
- if (isDocumentEntity)
+ if (!isDocumentEntity)
current = fragment = doc.CreateDocumentFragment ();
}
// Properties
public XmlNode Document {
- get { return isDocumentEntity ? (XmlNode)fragment : (XmlNode)doc; }
+ get { return isDocumentEntity ? (XmlNode)doc : (XmlNode)fragment; }
}
public override WriteState WriteState {
throw new InvalidOperationException (String.Format ("Current state is not acceptable for {0}.", n.NodeType));
if (state != XmlNodeType.Element)
- doc.AppendChild (n);
+ Document.AppendChild (n);
else if (attribute != null)
attribute.AppendChild (n);
else
XmlElement el = doc.CreateElement (prefix, name, ns);
if (current == null) {
- doc.AppendChild (el);
+ Document.AppendChild (el);
state = XmlNodeType.Element;
} else {
current.AppendChild (el);
if (!forceFull && current.FirstChild == null)
((XmlElement) current).IsEmpty = true;
- if (current.ParentNode == doc)
+ if (isDocumentEntity && current.ParentNode == doc)
state = XmlNodeType.EndElement;
else
- current = current.ParentNode as XmlElement;
+ current = current.ParentNode;
}
// StartAttribute