兼容在IE和Firefox浏览器下操作XML(英)
2008-07-03 06:30
357 查看
本文摘自http://www.w3schools.com
To read and update - create and manipulate - an XML document, you will need an XML parser.
微软的XML解析器是IE5或更高版本附带的COM组件. 在安装IE后,就可以在脚本中使用这个解析器
Microsoft's XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
微软的XML解析器支持所有必要的功能, 包括转换节点树, 存取节点及它们的属性, 插入和删除节点, 及把节点树转换回XML
The following table lists the most commonly used node types supported by Microsoft's XML parser:
下表列出了微软XML解析器最常用的节点类型
MSXML Parser 2.5 is the XML parser that is shipped with Windows 2000 and IE 5.5.
MSXML解析器2.5版封装在WINDOWS2000和IE5.5中
MSXML Parser 3.0 is the XML parser that is shipped with IE 6.0 and Windows XP.
MSXML解析器3.0版封装在WINDOWS XP和IE6.0中
The MSXML 3.0 parser features:
JavaScript, VBScript, Perl
c808
, VB, Java, C++, etc. support
Complete XML support
Full DOM and Namespace support
DTD and validation
Complete XSLT and XPath support
SAX2 support
Server-safe HTTP
MSXML 3.0版特点
支持JavaScript, VBScript, Perl, VB, Java, C++等
完全支持XML
完全支持DOM和Namespace
支持DTD和验证
完全支持XSLT和XPath
支持SAX2
支持HTTP服务器端安全(Server-safe HTTP)
To create an instance of Microsoft's XML parser with JavaScript, use the following code:
对于JavaScript, 使用下面的代码创建一个微软XML解析器实例
To create an instance of Microsoft's XML parser with VBScript, use the following code:
对于VBScript, 使用下面的代码创建一个微软XML解析器实例
To create an instance of Microsoft's XML parser in an ASP page (using VBScript), use the following code:
对于服务器端VBScript, 使用下面的代码创建一个微软XML解析器实例
The following code loads an existing XML document ("note.xml") into Microsoft's XML parser:
下面的代码将一个XML文档"note.xml"读入微软XML解析器
The first line of the script above creates an instance of the Microsoft XML parser. The third line tells the parser to load an XML document called "note.xml". The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.
Mozilla also supports parsing of XML data using JavaScript. The parsed data can be displayed as HTML.
To create an instance of the XML parser with JavaScript in Mozilla browsers, use the following code:
The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.
The following code loads an existing XML document ("note.xml") into Mozillas' XML parser:
The first line of the script above creates an instance of the XML parser. The second line tells the parser to load an XML document called "note.xml".
Try it yourself
The following code loads a text string into Microsoft's XML parser:
If you have Internet Explorer, you can try it yourself.
To read and update - create and manipulate - an XML document, you will need an XML parser.
Microsoft's XML Parser
Microsoft's XML parser is a COM component that comes with Internet Explorer 5 and higher. Once you have installed Internet Explorer, the parser is available to scripts.微软的XML解析器是IE5或更高版本附带的COM组件. 在安装IE后,就可以在脚本中使用这个解析器
Microsoft's XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
微软的XML解析器支持所有必要的功能, 包括转换节点树, 存取节点及它们的属性, 插入和删除节点, 及把节点树转换回XML
The following table lists the most commonly used node types supported by Microsoft's XML parser:
下表列出了微软XML解析器最常用的节点类型
Node Type | Example |
---|---|
Processing instruction | <?xml version="1.0"?> |
Element | <drink type="beer">Carlsberg</drink> |
Attribute | type="beer" |
Text | Carlsberg |
MSXML解析器2.5版封装在WINDOWS2000和IE5.5中
MSXML Parser 3.0 is the XML parser that is shipped with IE 6.0 and Windows XP.
MSXML解析器3.0版封装在WINDOWS XP和IE6.0中
The MSXML 3.0 parser features:
JavaScript, VBScript, Perl
c808
, VB, Java, C++, etc. support
Complete XML support
Full DOM and Namespace support
DTD and validation
Complete XSLT and XPath support
SAX2 support
Server-safe HTTP
MSXML 3.0版特点
支持JavaScript, VBScript, Perl, VB, Java, C++等
完全支持XML
完全支持DOM和Namespace
支持DTD和验证
完全支持XSLT和XPath
支持SAX2
支持HTTP服务器端安全(Server-safe HTTP)
To create an instance of Microsoft's XML parser with JavaScript, use the following code:
对于JavaScript, 使用下面的代码创建一个微软XML解析器实例
对于VBScript, 使用下面的代码创建一个微软XML解析器实例
set xmlDoc=CreateObject("Microsoft.XMLDOM") |
对于服务器端VBScript, 使用下面的代码创建一个微软XML解析器实例
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") |
下面的代码将一个XML文档"note.xml"读入微软XML解析器
<script type="text/javascript"> ... ... ... </script> |
XML Parser in Mozilla Browsers
Plain XML documents are displayed in a tree-like structure in Mozilla (just like IE).Mozilla also supports parsing of XML data using JavaScript. The parsed data can be displayed as HTML.
To create an instance of the XML parser with JavaScript in Mozilla browsers, use the following code:
The following code loads an existing XML document ("note.xml") into Mozillas' XML parser:
<script type="text/javascript"> ... ... ... </script> |
Loading an XML File - A Cross browser Example
The following example is a cross browser example that loads an existing XML document ("note.xml") into the XML parser:<html> <head> <script type="text/javascript"> var xmlDoc function loadXML() { //load xml file // code for IE if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.("note.xml"); getmessage() } // code for Mozilla, etc. else if (document.implementation && document.implementation.createDocument) { xmlDoc= document.implementation.createDocument("","",null); xmlDoc.("note.xml"); xmlDoc.onload=getmessage } else { alert('Your browser cannot handle this script'); } } function getmessage() { document.getElementById("to").innerHTML= xmlDoc.getElementsByTagName("to")[0].firstChild.nodeValue document.getElementById("from").innerHTML= xmlDoc.getElementsByTagName("from")[0].firstChild.nodeValue document.getElementById("message").innerHTML= xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue } </script> </head> <body onload="loadXML()" bgcolor="yellow"> <h1>W3Schools Internal Note</h1> <p><b>To:</b> <span id="to"></span><br /> <b>From:</b> <span id="from"></span> <hr /> <b>Message:</b> <span id="message"></span> </p> </body> </html> |
Loading XML Text Into the Parser
Internet Explorer supports two ways of loading XML into a document object: the load() method and the loadXML() method. The load() method loads an XML file and the loadXML() method loads a text string that contains XML code.The following code loads a text string into Microsoft's XML parser:
<script type="text/javascript"> var txt="<note>" txt=txt+"<to>Tove</to><from>Jani</from>" txt=txt+"<heading>Reminder</heading>" txt=txt+"<body>Don't forget me this weekend!</body>" txt=txt+"</note>" var xmlDoc=new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.(txt) ... ... ... </script> |
相关文章推荐
- 在javascript中操作兼容IE/Firefox浏览器的XMLDOM及扩展[最新]
- 兼容IE和firefox 操作XML的 javascript
- [JavaScript] 兼容IE、FireFox、Chrome等浏览器的xml处理函数(xml同步/异步加载、xsl转换、selectSingleNode、selectNodes)
- [JavaScript] 兼容IE、FireFox、Chrome等浏览器的xml处理函数(xml同步/异步加载、xsl转换、selectSingleNode、selectNodes)
- [JavaScript] 兼容IE、FireFox、Chrome等浏览器的xml处理函数(xml同步/异步加载、xsl转换、selectSingleNode、selectNodes)
- 利用AJAX,得到XML和JSON信息,不用JQuery等UI框架,兼容 IE、Firefox、Chrome、Safari、Opera 等浏览器。
- js操作XML文件兼容IE与FireFox
- asp+js 操作 XML 兼容IE 火狐 Safari 浏览器
- js操作XML文件兼容IE与FireFox
- 兼容 IE和FireFox的 XML_HTTP和浏览器共享同一个SessionID
- javascript 操作剪切板 ie firefox 兼容
- JS 预览上传图片,兼容IE、firefox等所有浏览器
- php 实现文件下载,兼容IE、Firefox、Chrome等浏览器
- 如何使用JS脚本处理XML字符串或XML文件(适用于IE、Opera、Firefox浏览器)
- Iframe自适应高度兼容ie,firefox多浏览器
- [转]获取xml节点值和属性值(兼容ie和firefox)
- CSS图片倒影效果兼容firefox、IE等各主流浏览器
- JS对select动态添加options操作[IE&FireFox兼容]
- Javascript兼容IE和Firefox浏览器技巧<转>
- CSS浏览器兼容问题整理(IE6.0、IE7.0+ 与 FireFox)