Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace System.Xml
- {
- public class XmlTextWriter
- {
- /// <summary>
- /// Internal writer object
- /// </summary>
- internal StringWriter XmlDoc { get; set; }
- /// <summary>
- /// internal storage for current opened element
- /// </summary>
- private Stack<string> openElements;
- public XmlTextWriter()
- {
- if (this.XmlDoc == null)
- {
- this.XmlDoc = new StringWriter();
- }
- openElements = new Stack<string>();
- }
- public XmlTextWriter(StringWriter writer) : this()
- {
- this.XmlDoc = writer;
- }
- /// <summary>
- /// Writes the header of the xml
- /// </summary>
- public void WriteStartDocument()
- {
- this.WriteStartDocument(false);
- }
- /// <summary>
- /// Writes the header of the xml
- /// </summary>
- /// <param name="standalone">defines if standalone or not</param>
- public void WriteStartDocument(bool standalone)
- {
- string standaloneText = "no";
- if (standalone)
- {
- standaloneText = "yes";
- }
- this.XmlDoc.Write("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"" + standaloneText + "\"?>");
- }
- /// <summary>
- /// Writes a raw string into the document
- /// </summary>
- /// <param name="data">Data to write</param>
- public void WriteRaw(string data)
- {
- this.XmlDoc.Write(data);
- }
- /// <summary>
- /// Open a new XmlElement
- /// </summary>
- /// <param name="elementName">Name of the Element</param>
- public void WriteStartElement(string elementName)
- {
- this.XmlDoc.Write("<" + elementName + ">");
- openElements.Push(elementName);
- }
- /// <summary>
- /// Close an XmlElement
- /// </summary>
- public void WriteEndElement()
- {
- this.XmlDoc.Write("</" + openElements.Pop() + ">");
- }
- /// <summary>
- /// Writes an XmlElement string
- /// </summary>
- /// <param name="elementName">Name of the Element</param>
- /// <param name="Data">Data to write</param>
- public void WriteElementString(string elementName, string Data)
- {
- this.XmlDoc.Write("<" + elementName + ">");
- this.XmlDoc.Write(Data);
- this.XmlDoc.Write("</" + elementName + ">");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement