Using EmEditor, when looking at an XML document, it's always confusing because of the format confusion. This is a EmEditor macro to automatically format the XML. Download:formatxml.rar (1,021.00 bytes)
The following section is the JavaScript formatted XML code for this page version.
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<html>
<head>
<meta http-equiv=content-type content= "text/html; Charset=utf-8 ">
<title>xml formatting Tools </title>
<script type= "Text/javascript" >
String.prototype.removeLineEnd = function ()
{
return This.replace (/(<.+?s+?) (?: ns*? (.+?=".*?")) /g, ' $ $ '
}
function Formatxml (text)
{
Remove the extra space
text = ' n ' + text.replace (/(<w+) (s.*?>)/g,function ($, name, props)
{
return name + ' + props.replace (/s+ (w+=)/g, "$");
}). replace (/>s*?</g, ">n<");
//Coding the annotation
Text = Text.replace (/n/g, ' R '). Replace (/<!--(. +?) -->/g,function ($, text)
{
var ret = ' <!--' + escape (text) + '--> ';
//alert (ret);
return ret;
}). replace (/r/g, ' n ');
//Adjustment format
var rgx =/N (< ([^?]). +?) (?: s|s*?>|s*? (/) >) (?:. *? (?:(:( /) >) | (?:< (/) 2>)) /MG;
var nodestack = [];
var output = Text.replace (Rgx,function ($0,all,name,isbegin,isclosefull1,isclosefull2, isfull1,isfull2) {
var isclosed = (IsCloseFull1 = = '/") | | (IsCloseFull2 = = '/') | | (IsFull1 = = '/') | | (IsFull2 = = '/');
//alert ([all,isclosed].join (' = '));
var prefix = ';
if (Isbegin = = '! ')
{
prefix = getprefix (nodestack.length);
}
Else
{
if (isbegin!= '/')
{
prefix = Getprefix (nodestack.length);
if (!isclosed)
{
Nodestack.push (name);
}
}
Else
{
Nodestack.pop ();
prefix = getprefix (nodestack.length);
}
}
var ret = ' n ' + prefix + all;
return ret;
});
var prefixspace =-1;
var outputtext = output.substring (1);
//alert (Outputtext);
//The annotation is restored and decoded, and the format is adjusted
outputtext = Outputtext.replace (/n/g, ' R '). Replace (/(s*) <!--(. +?) -->/g,function ($, prefix, text)
{
//alert ([' [', prefix, ']= ', Prefix.length].join (')];
if (prefix.charat (0) = = ' R ')
prefix = prefix.substring (1);
Text = unescape (text). Replace (/r/g, ' n ');
var ret = ' n ' + prefix + ' <!--' + text.replace (/^s*/mg, prefix) + '--> ';
//alert (ret);
return ret;
});
return Outputtext.replace (/s+$/g, '). Replace (/r/g, ' RN ');
}
function Getprefix (prefixindex)
{
var span = ';
var output = [];
for (var i = 0; i < Prefixindex ++i)
{
Output.push (span);
}
return Output.join (");
}
function Btnformat_click ()
{
var $ = document.getElementById;
$ (' output '). Value = Formatxml ($ (' input '). Value);
}
</script>
</head>
<body>
<textarea id= "input" style= "width:100%;height:45%;" ></textarea>
<div style= "margin:0px auto;" ><input type= "button" id= "Btnformat" onclick= "Btnformat_click ()" value= "format" style= "width:50%;height:10%;" /></div>
<textarea id= "Output" style= "width:100%;height:45%;" ></textarea>
</body>
</html>