Saturday, May 30, 2009

Read an xml file, twist it with an xsl file and then write to a string

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;

class WriteXMLViaXSL
{
public static void Main(string[] args)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(args[0]);

XslTransform xslTransform = new XslTransform();
xslTransform.Load(args[1]);


StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
xmlTextWriter.Formatting = Formatting.Indented;
xslTransform.Transform(xmlDocument, null, xmlTextWriter);

xmlTextWriter.Flush();
Console.Write(stringWriter.ToString());
}
}

2 comments:

  1. The XslTransform class is obsolete now.. instead you can use enhanced class XslCompiledTransform

    ReplyDelete
  2. Thanks for Comment It May Helpm Others

    ReplyDelete