| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- //
- // System.Xml.XmlTextWriter
- //
- // Author:
- // Kral Ferch <[email protected]>
- //
- // (C) 2002 Kral Ferch
- //
- using System;
- using System.Collections;
- using System.IO;
- using System.Text;
- namespace System.Xml
- {
- public class XmlTextWriter : XmlWriter
- {
- #region Fields
- protected TextWriter w;
- protected bool openWriter = true;
- protected bool openStartElement;
- protected Stack openElements = new Stack ();
- protected XmlNamespaceManager namespaceManager = new XmlNamespaceManager (new NameTable ());
- #endregion
- #region Constructors
- public XmlTextWriter (TextWriter w) : base ()
- {
- this.w = w;
- }
- public XmlTextWriter (Stream w, Encoding encoding) : base ()
- {
- this.w = new StreamWriter(w, encoding);
- }
- public XmlTextWriter (string filename, Encoding encoding) : base ()
- {
- this.w = new StreamWriter(filename, false, encoding);
- }
- #endregion
- #region Properties
- [MonoTODO]
- public Stream BaseStream {
- get { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public Formatting Formatting {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public int Indentation {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public char IndentChar {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public bool Namespaces {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public char QuoteChar {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public override WriteState WriteState {
- get { throw new NotImplementedException(); }
- }
-
- [MonoTODO]
- public override string XmlLang {
- get { throw new NotImplementedException(); }
- }
- [MonoTODO]
- public override XmlSpace XmlSpace {
- get { throw new NotImplementedException(); }
- }
- #endregion
- #region Methods
- private void CheckOpenWriter ()
- {
- if (!openWriter) {
- throw new InvalidOperationException ("The Writer is closed.");
- }
- }
- public override void Close ()
- {
- while (openElements.Count > 0) {
- WriteEndElement();
- }
- w.Close();
- openWriter = false;
- }
- private void CloseStartElement ()
- {
- if (openStartElement)
- {
- w.Write(">");
- openStartElement = false;
- }
- }
- [MonoTODO]
- public override void Flush ()
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override string LookupPrefix (string ns)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteBase64 (byte[] buffer, int index, int count)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteBinHex (byte[] buffer, int index, int count)
- {
- throw new NotImplementedException ();
- }
- public override void WriteCData (string text)
- {
- if (text.IndexOf("]]>") > 0)
- {
- throw new ArgumentException ();
- }
- CheckOpenWriter ();
- CloseStartElement ();
- w.Write("<![CDATA[{0}]]>", text);
- }
- [MonoTODO]
- public override void WriteCharEntity (char ch)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteChars (char[] buffer, int index, int count)
- {
- throw new NotImplementedException ();
- }
- public override void WriteComment (string text)
- {
- if ((text.EndsWith("-")) || (text.IndexOf("-->") > 0)) {
- throw new ArgumentException ();
- }
- CheckOpenWriter ();
- CloseStartElement ();
- w.Write ("<!--{0}-->", text);
- }
- [MonoTODO]
- public override void WriteDocType (string name, string pubid, string sysid, string subset)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteEndAttribute ()
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteEndDocument ()
- {
- throw new NotImplementedException ();
- }
- public override void WriteEndElement ()
- {
- if (openStartElement) {
- w.Write (" />");
- openElements.Pop ();
- openStartElement = false;
- }
- else {
- w.Write ("</{0}>", openElements.Pop ());
- namespaceManager.PopScope();
- }
- }
- [MonoTODO]
- public override void WriteEntityRef (string name)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteFullEndElement ()
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteName (string name)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteNmToken (string name)
- {
- throw new NotImplementedException ();
- }
- public override void WriteProcessingInstruction (string name, string text)
- {
- if ((name == null) || (name == string.Empty) || (name.IndexOf("?>") > 0) || (text.IndexOf("?>") > 0)) {
- throw new ArgumentException ();
- }
- CheckOpenWriter ();
- CloseStartElement ();
- w.Write ("<?{0} {1}?>", name, text);
- }
- [MonoTODO]
- public override void WriteQualifiedName (string localName, string ns)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteRaw (string data)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteRaw (char[] buffer, int index, int count)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteStartAttribute (string prefix, string localName, string ns)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteStartDocument ()
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteStartDocument (bool standalone)
- {
- throw new NotImplementedException ();
- }
- public override void WriteStartElement (string prefix, string localName, string ns)
- {
- string formatXmlns = "";
- string formatPrefix = "";
- if ((prefix != String.Empty) && (ns == String.Empty))
- throw new ArgumentException ("Cannot use a prefix with an empty namespace.");
- CheckOpenWriter ();
- CloseStartElement ();
- if (ns != String.Empty) {
- string existingPrefix = namespaceManager.LookupPrefix (ns);
- if (prefix == String.Empty)
- prefix = existingPrefix;
- if (prefix != existingPrefix)
- formatXmlns = " xmlns:" + prefix + "=\"" + ns + "\"";
- else if (existingPrefix == String.Empty)
- formatXmlns = " xmlns=\"" + ns + "\"";
- }
- else if ((prefix == String.Empty) && (namespaceManager.LookupNamespace(prefix) != String.Empty)) {
- formatXmlns = " xmlns=\"\"";
- }
- if (prefix != String.Empty) {
- formatPrefix = prefix + ":";
- }
- w.Write ("<{0}{1}{2}", formatPrefix, localName, formatXmlns);
- openElements.Push (formatPrefix + localName);
- openStartElement = true;
- namespaceManager.PushScope ();
- namespaceManager.AddNamespace (prefix, ns);
- }
- [MonoTODO("Haven't done any entity replacements yet.")]
- public override void WriteString (string text)
- {
- if (text != String.Empty) {
- CheckOpenWriter ();
- CloseStartElement ();
- w.Write (text);
- }
- }
- [MonoTODO]
- public override void WriteSurrogateCharEntity (char lowChar, char highChar)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override void WriteWhitespace (string ws)
- {
- throw new NotImplementedException ();
- }
- #endregion
- }
- }
|