writer

Shows how to write an XML file

Download xmlwriter.zip

Synopsis:

xmlwriter.cs


xmlwriter.cs

Synopsis
//WARNING! NO UNITTEST
using System;
using System.Collections;
using System.Xml;

public class xmlwriter
{
  private readonly string cRootTag = "items";
  private readonly string cNodeTag = "item";

  public void Save(string fname, string stylesheet, ArrayList items)
  {
    XmlTextWriter xtw = new XmlTextWriter(fname, null);
    xtw.WriteStartDocument();
    xtw.Formatting = System.Xml.Formatting.Indented;
    if (stylesheet != null)
    {
      xtw.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" + stylesheet + "'");
    }
    xtw.WriteStartElement(cRootTag);
    foreach(string desc in items)
    {
      xtw.WriteStartElement(cNodeTag);
      xtw.WriteElementString("desc", desc);
      //xtw.WriteElementString("category", category);
      //etc.
      xtw.WriteEndElement();
    }
    xtw.WriteEndDocument();
    xtw.Flush();
    xtw.Close();
  }
}






Contact me about content on this page using john_web-at-arrizza-dot-com
For Web Master or site problems contact: webadmin-at-arrizza-dot-com
Copyright John Arrizza (c) 2001-2010