<?xml version="1.0" encoding="gb2312"?>
<threads>
<thread>
<title>我是</title>
<author>大大</author>
<content>飞交换机</content>
</thread>
<thread><title>1111</title><author>111111</author><content>111111111</content></thread>
<thread><title>11111111111111111111</title><author>1111111111</author><content>11111111111111111111</content></thread>
<thread><title>11111</title><author>111111</author><content>111</content></thread>
</threads>
这是我用PHP动态修改后的XML文件,排版格式比较乱,有什么办法能把XML文件格式排版整理好?
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("d:\\test1.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError
alert("You have error " + myErr.reason);
} else {
alert(xmlDoc.xml);
}formatDoc(xmlDoc, "d:\\test1.xml");function formatDoc(oDoc, sFilename){
var oSAXWriter, oSAXReader; oSAXWriter = new ActiveXObject("Msxml2.MXXMLWriter");
oSAXReader = new ActiveXObject("Msxml2.SAXXMLReader");
with(oSAXWriter){
encoding = "UTF-8";
byteOrderMark = true;
standalone = true;
omitXMLDeclaration = false;
indent = true;
}
with(oSAXReader){
contentHandler = oSAXWriter;
dtdHandler = oSAXWriter;
errorHandler = oSAXWriter;
putProperty("http://xml.org/sax/properties/lexical-handler", oSAXWriter);
putProperty("http://xml.org/sax/properties/declaration-handler", oSAXWriter);
parse(oDoc);
}
var s = oSAXWriter.output;
s = s.replace(/encoding\="UTF\-16"/,"encoding=\"GB2312\"");
alert(s);
var fso = new ActiveXObject("Scripting.FileSystemObject")
var file = fso.OpenTextFile(sFilename,2,true,-2)
file.Write(s);
file.Close();}function alert(s){WScript.Echo(s);}