Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PowerShell to convert XML to HTML

Tags:

powershell

xml

I have an XML file:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='file:///C:/Program%20Files/Application/log_format.xsl'?>
<!DOCTYPE log [<!ENTITY data SYSTEM 'data/20130408.dat'>]>
<log xmlns="runtime:log">&data;</log>

The xsl file transforms it into HTML. I can't open the file in IE just fine and view the expected results. I would like to via a PowerShell script convert this in plain HTML. How would I go about that?

like image 742
Justin808 Avatar asked Mar 24 '23 09:03

Justin808


2 Answers

This blog entry has a code snippet that should work. It uses the System.Xml.Xsl.XslCompiledTransform .NET class to do the XSL transformation. The rest is just for getting the input and displaying the output.

This was originally a comment, but I guess I'll make it an answer so it's easier for other people who are searching for a solution.

like image 164
austin Avatar answered Mar 29 '23 21:03

austin


The PowerShell Community Extensions has a Convert-Xml that will do an XSL transform on the XML. If the resulting file isn't valid HTML then you need to work on the XSL file.

like image 36
Keith Hill Avatar answered Mar 29 '23 19:03

Keith Hill