作者:朱金灿
来源:http://blog.csdn.net/clever101
JScript读取XML文件需要考虑msxml组件的多个版本,稳妥的做法是将所有版本都列出来。
<?xml version="1.0" encoding="GB2312" ?> <Binary> <Item name="a.exe" /> <Item name="b.dll" /> <Item name="c.dll" /> </Binary>
读取该xml文件的JScript如下:
main(); function main() { var xmlDoc = null; var signatures = [ "Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","Msxml2.DOMDocument","Microsoft.XmlDom"]; for (var index = 0; index < signatures.length; index++) { try { xmlDoc = new ActiveXObject(signatures[index]); } catch (e) { //继续尝试更低版本 } } xmlDoc.async = false; xmlDoc.resolveExternals = false; var strXmlPath = “D:\\test.xml”; xmlDoc.load(strXmlPath); if (xmlDoc.parseError.errorCode != 0) { var myError = xmlDoc.parseError; WScript.Echo("打开xml文件失败: " + myError); } else { var BinGroup = xmlDoc.getElementsByTagName("Item"); for (var i = 0; i < BinGroup.length; i++) { var strBinName = BinGroup.item(i).getAttribute("name"); WScript.Echo(strBinName); } } }原文链接:https://www.f2er.com/xml/300306.html