20080104

Convert XML to HTML using NUnit

[Test]

public void Convert_xml_to_html()

{

string xml = @"<configuration>

...

<system.diagnostics>

<trace autoflush='true' />

<sources>

<source name='System.ServiceModel'

switchValue='Information, ActivityTracing'

propagateActivity='true'>

<listeners>

<add name='FuckingAwesomeWCFLogger'

type='System.Diagnostics.XmlWriterTraceListener'

initializeData='FuckingAwesomeWCF.log' />

</listeners>

</source>

</sources>

</system.diagnostics>

...

</configuration>";

Console.Out.WriteLine(xml.Replace("<", "&lt;").Replace(">", "&gt;").Replace("'", "&quot;").Replace("/", "&#47;").Replace("=", "&#61;"));

}

1 comments:

Eric Liu said...

Depending on what you need this for, there is also the System.Web.HttpUtility.HtmlEncode method available. I think it produces something slightly different than your implementation though...