Sunday, March 15, 2009

XML Formatting in Editplus

Are you tried of formatting the xml ? Here the solution to automate the process in Editplus.

Download the latest version of Editplus.

Step 1 : Save the below script as xmlformattingscript.js.

var stdin  = WScript.StdIn;
var stdout = WScript.StdOut;
var xml = WScript.createObject("MSXML2.DomDocument");
xml.loadXML(stdin.ReadAll().replace(/\t/g, '').replace(/\r|\n/g, '').replace(/\>\</g, '>\n<'));
stdout.Write(xml.xml.substr(0, xml.xml.length-2));

Step 2 : Open Editplus and navigate to Tools –> Configure user tools… –> Add tools –> Program

Step 3 : In Menu text box type XML Formatter

Step 4 : In Command box type

cscript //NoLogo “path to xmlformattingscript.js”

Step 5 : Check the “Run as text filter”.

Step 6 : Apply and OK.

Testing the tool

1) Open unformatted xml file.

Example

<root><text>

</text>                  </root>

2) Tools –> XML Formatter

Formatted xml

<root>

      <test>

      </test>

</root>

Reference http://editplus.info/wiki/Writing_a_text_filter

Enjoy ;)

~Barath.