Skip to content

Transform XML Strings

This one is a quickie. It applies XML transformations where the source and destination are both strings.

string xml = txtXml.Text;
string xslString = txtTranstring.Text;
string transformedXml = string.Empty;

XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(new XmlTextReader(new StringReader(xslString)));
using (var stringWriter = new StringWriter())
    using (var xmlWriter = XmlWriter.Create(stringWriter))
        xsl.Transform(new XmlTextReader(new StringReader(xml)), xmlWriter);

    transformedXml = stringWriter.ToString();

txtResult.Text = transformedXml;
Published inC#XML

Comments are closed.