Format XML string in VBScript -


Hey a quick question at the end of a long day.

I have a string of unformatted XML (no whitespacing) and I want to create a VBScript function that accepts it as its parameter and create XML format with string tabs and new-rows

I have taken a good look around the net and have come close with this

Because 'MSXML2.DomDocument' does not support writing for a string from the object what I can tell Did not work.

Ive tried to use different properties of the object (tried to 'XML', 'no benefit text', and 'xml.text') all.

Simply put, I need a string of dirty XML, and a string of formatted XML outdoors

All credits go to Robert McMurray; I recreated my script in the function:

  clear the options' ******************************************************************** **************************************************************************************************** **** ********************************************************************************************** ***************** Function prettyXml (ByVal sDirty) '**************** ********* ********* Keep the white space between tags (XSL is required for conversion.) '***************************************************** ************** sDirty = Change (sDirty, "> <" "& gt;" & amp; vbCrLf & amp; "& Lt;") '****************************************************************************************** * Create an XSL stylesheet for change. '******************************** objXSL: set objXSL = WScript.CreateObject ("Msxml2.DOMDocument") objXSL.loadXML "& lt; XSL: Stylesheet version =" 1.0 "" xmlns: XSL = "" http://www.w3.org/1999/XSL/Transform "" & gt; " & Amp; _ "& Lt; xsl: output method =" "xml" "indent =" "yes" "/>" & amp; _ "& Lt; xsl: template match =" "/" & gt; " & Amp; _ "& Lt; xsl: copy-of select =" "." "/ & Gt; & Amp; _ "& Lt; / xsl: template & gt;" & Amp; _ "& Lt; / xsl: stylesheet & gt;" '************************************************************************************************** ************************ XML Conversion '********* ********************* objXML: set objXML = WScript.CreateObject ("Msxml2.DOMDocument") objXML.loadXml SDirty objXML.transformNode objXSL prettyXml = objXML.xml termination function dull sTest: sTest = "       

Product:

  cscript robmcm-2.vbs & lt; A & gt; & Lt; P & gt; & Lt; C / & gt; & Lt; / P & gt; & Lt; / A & gt; ---------- & lt; A & gt; & Lt; P & gt; & Lt; C / & gt; & Lt; / P & gt; & Lt; / A & gt; On the other side:  

You should not use the above version unless you have studied.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -