//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();
}
}
|