+ -
当前位置:首页 → 问答吧 → FF怎么解析XML

FF怎么解析XML

时间:2005-11-17

来源:互联网

IE下用 Microsoft.XMLFOM
FireFox下面呢

作者: fkiori   发布时间: 2005-11-17

<html>
<head>
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
// code for Mozilla, etc                 .FireFox也包括在其中了吧。。。
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  alert("XML data OK")
  document.getElementById('A1').innerHTML=xmlhttp.status
  document.getElementById('A2').innerHTML=xmlhttp.statusText
  document.getElementById('A3').innerHTML=xmlhttp.responseText
  }
  else
  {
  alert("Problem retrieving XML data:" + xmlhttp.statusText)
  }
  }
}

</script>
</head>

<body onload="loadXMLDoc('note.xml')">
<h2>Using the HttpRequest Object</h2>

<p><b>status:</b>
<span id="A1"></span>
</p>

<p><b>status text:</b>
<span id="A2"></span>
</p>

<p><b>response:</b>
<br><span id="A3"></span>
</p>

</body>
</html>

作者: 单身   发布时间: 2005-11-19

xmlhttp=new XMLHttpRequest()

作者: 单身   发布时间: 2005-11-19

打错了,欧要得是可以代替 Microsoft.XMLDOM的东西
不是 Microsoft.XMLHTTP

作者: fkiori   发布时间: 2005-11-21

XML Parser in Mozilla(firefox) 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:

var xmlDoc=document.implementation.createDocument("ns","root",null)

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:

<script type="text/javascript">
var xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");
...
...
...
</script>
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".

作者: 单身   发布时间: 2005-11-21