< script language="JavaScript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
// ....... processing the document goes here
< /script>
这个脚本的第一行创建Microsoft XML 分解器的一个例示。第二行关闭不对称装载,在文档完全装载之前,要确保分解器不会继续执行。第三行告诉分解器装载一个叫做note.xml的XML文档。
向分解器中装载纯XML文本
还可以从文本字符串装载XML文本。 下面的代码将一个文本字符串装载到XML分解器中:
< script language="JavaScript">
var text="< note>"
text=text+"< to>Tove< /to>< from>Jani< /from>"
text=text+"< heading>Reminder< /heading>"
text=text+"< body>Don't forget me this weekend!< /body>"
text=text+"< /note>"
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(text)
// ....... processing the document goes here
< /script>