protected bool openStartElement = false;
protected bool openStartAttribute = false;
protected bool documentStarted = false;
- protected bool namespaces = true;
+ private bool namespaces = true;
protected bool openAttribute = false;
protected bool attributeWrittenForElement = false;
protected Stack openElements = new Stack ();
- protected Formatting formatting = Formatting.None;
- protected int indentation = 2;
- protected char indentChar = ' ';
+ private Formatting formatting = Formatting.None;
+ private int indentation = 2;
+ private char indentChar = ' ';
protected string indentChars = " ";
- protected char quoteChar = '\"';
+ private char quoteChar = '\"';
protected int indentLevel = 0;
protected string indentFormatting;
protected Stream baseStream = null;
public override void Close ()
{
- while (openElements.Count > 0) {
- WriteEndElement();
- }
+ CloseOpenAttributeAndElements ();
w.Close();
ws = WriteState.Closed;
openWriter = false;
}
+ private void CloseOpenAttributeAndElements ()
+ {
+ if (openAttribute)
+ WriteEndAttribute ();
+
+ while (openElements.Count > 0) {
+ WriteEndElement();
+ }
+ }
+
private void CloseStartElement ()
{
- if (openStartElement)
- {
+ if (openStartElement) {
w.Write(">");
ws = WriteState.Content;
openStartElement = false;
openAttribute = false;
}
- [MonoTODO]
public override void WriteEndDocument ()
{
- throw new NotImplementedException ();
+ if ((ws == WriteState.Start) || (ws == WriteState.Prolog))
+ throw new ArgumentException ("This document does not have a root element.");
+
+ CloseOpenAttributeAndElements ();
+
+ ws = WriteState.Start;
}
public override void WriteEndElement ()
+ {
+ WriteEndElementInternal (false);
+ }
+
+ private void WriteEndElementInternal (bool fullEndElement)
{
if (openElements.Count == 0)
throw new InvalidOperationException("There was no XML start tag open.");
CheckState ();
if (openStartElement) {
- w.Write (" />");
+ if (openAttribute)
+ WriteEndAttribute ();
+
+ if (fullEndElement)
+ w.Write ("></{0}>", ((XmlTextWriterOpenElement)openElements.Peek ()).Name);
+ else
+ w.Write (" />");
+
openElements.Pop ();
openStartElement = false;
- }
- else {
+ } else {
w.Write ("{0}</{1}>", indentFormatting, openElements.Pop ());
}
throw new NotImplementedException ();
}
- [MonoTODO]
public override void WriteFullEndElement ()
{
- throw new NotImplementedException ();
+ WriteEndElementInternal (true);
}
[MonoTODO]