2 // System.Xml.XmlTextWriter
5 // Kral Ferch <kral_ferch@hotmail.com>
11 using System.Collections;
17 public class XmlTextWriter : XmlWriter
21 protected TextWriter w;
22 protected bool openWriter = true;
23 protected bool openStartElement;
24 protected Stack openElements = new Stack();
30 public XmlTextWriter (TextWriter w) : base ()
35 public XmlTextWriter (Stream w, Encoding encoding) : base ()
37 this.w = new StreamWriter(w, encoding);
40 public XmlTextWriter (string filename, Encoding encoding) : base ()
42 this.w = new StreamWriter(filename, false, encoding);
50 public Stream BaseStream {
51 get { throw new NotImplementedException(); }
56 public Formatting Formatting {
57 get { throw new NotImplementedException(); }
58 set { throw new NotImplementedException(); }
62 public int Indentation {
63 get { throw new NotImplementedException(); }
64 set { throw new NotImplementedException(); }
68 public char IndentChar {
69 get { throw new NotImplementedException(); }
70 set { throw new NotImplementedException(); }
74 public bool Namespaces {
75 get { throw new NotImplementedException(); }
76 set { throw new NotImplementedException(); }
80 public char QuoteChar {
81 get { throw new NotImplementedException(); }
82 set { throw new NotImplementedException(); }
86 public override WriteState WriteState {
87 get { throw new NotImplementedException(); }
91 public override string XmlLang {
92 get { throw new NotImplementedException(); }
96 public override XmlSpace XmlSpace {
97 get { throw new NotImplementedException(); }
104 private void CheckOpenWriter ()
107 throw new InvalidOperationException ("The Writer is closed.");
111 public override void Close ()
113 while (openElements.Count > 0) {
122 private void CloseStartElement ()
124 if (openStartElement)
127 openStartElement = false;
132 public override void Flush ()
134 throw new NotImplementedException ();
138 public override string LookupPrefix (string ns)
140 throw new NotImplementedException ();
144 public override void WriteBase64 (byte[] buffer, int index, int count)
146 throw new NotImplementedException ();
150 public override void WriteBinHex (byte[] buffer, int index, int count)
152 throw new NotImplementedException ();
155 public override void WriteCData (string text)
157 if (text.IndexOf("]]>") > 0)
159 throw new ArgumentException ();
163 CloseStartElement ();
165 w.Write("<![CDATA[{0}]]>", text);
169 public override void WriteCharEntity (char ch)
171 throw new NotImplementedException ();
175 public override void WriteChars (char[] buffer, int index, int count)
177 throw new NotImplementedException ();
180 public override void WriteComment (string text)
182 if ((text.EndsWith("-")) || (text.IndexOf("-->") > 0)) {
183 throw new ArgumentException ();
187 CloseStartElement ();
189 w.Write ("<!--{0}-->", text);
193 public override void WriteDocType (string name, string pubid, string sysid, string subset)
195 throw new NotImplementedException ();
199 public override void WriteEndAttribute ()
201 throw new NotImplementedException ();
205 public override void WriteEndDocument ()
207 throw new NotImplementedException ();
210 public override void WriteEndElement ()
212 if (openStartElement) {
215 openStartElement = false;
218 w.Write ("</{0}>", openElements.Pop ());
223 public override void WriteEntityRef (string name)
225 throw new NotImplementedException ();
229 public override void WriteFullEndElement ()
231 throw new NotImplementedException ();
235 public override void WriteName (string name)
237 throw new NotImplementedException ();
241 public override void WriteNmToken (string name)
243 throw new NotImplementedException ();
246 public override void WriteProcessingInstruction (string name, string text)
248 if ((name == null) || (name == string.Empty) || (name.IndexOf("?>") > 0) || (text.IndexOf("?>") > 0)) {
249 throw new ArgumentException ();
253 CloseStartElement ();
255 w.Write ("<?{0} {1}?>", name, text);
259 public override void WriteQualifiedName (string localName, string ns)
261 throw new NotImplementedException ();
265 public override void WriteRaw (string data)
267 throw new NotImplementedException ();
271 public override void WriteRaw (char[] buffer, int index, int count)
273 throw new NotImplementedException ();
277 public override void WriteStartAttribute (string prefix, string localName, string ns)
279 throw new NotImplementedException ();
283 public override void WriteStartDocument ()
285 throw new NotImplementedException ();
289 public override void WriteStartDocument (bool standalone)
291 throw new NotImplementedException ();
294 [MonoTODO("Not dealing with prefix and ns yet.")]
295 public override void WriteStartElement (string prefix, string localName, string ns)
298 CloseStartElement ();
299 w.Write ("<{0}", localName);
300 openElements.Push (localName);
301 openStartElement = true;
304 [MonoTODO("Haven't done any entity replacements yet.")]
305 public override void WriteString (string text)
308 CloseStartElement ();
313 public override void WriteSurrogateCharEntity (char lowChar, char highChar)
315 throw new NotImplementedException ();
319 public override void WriteWhitespace (string ws)
321 throw new NotImplementedException ();