function getName(fname, text)
{
var xmlFile = "piante.xml";
var xmlDoc;
if(typeof window.DOMParser != "undefined") {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",xmlFile,false);
if (xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
else{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(xmlFile);
}
var x=xmlDoc.getElementsByTagName("ROW");
document.write(x.length);
for (var i=0;i<x.length;i++){
var y=x[i].getElementsByTagName("DATA");
if(y[1].childNodes[0].nodeValue == text){
var z= y[0].childNodes[0].nodeValue;
return z;}
}
}
这里我的文件.xml
<?xml version="1.0" encoding="UTF-8" ?>
<FMPXMLRESULT
xmlns="http://www.filemaker.com/fmpxmlresult"><ERRORCODE>0</ERRORCODE><PRODUCT
BUILD="12-06-2016" NAME="FileMaker" VERSION="ProAdvanced 15.0.3"/><DATABASE
DATEFORMAT="D/m/yyyy" LAYOUT="" NAME="IndexHorti v3.12.fmp12" RECORDS="586"
TIMEFORMAT="k:mm:ss "/>
<METADATA><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Gen Spe con spazio"
TYPE="TEXT"/><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Localizzazione esemplare LAST"
TYPE="TEXT"/><FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Link WEB"
TYPE="TEXT"/></METADATA>
<RESULTSET FOUND="2">
<ROW MODID="56" RECORDID="20055">
<COL><DATA>Acanthus mollisL.</DATA></COL>
<COL><DATA>01-02-01-23</DATA></COL>
<COL><DATA>www.corriere.it</DATA></COL></ROW>
<ROW MODID="12" RECORDID="20057">
<COL><DATA>Achillea millefolium L.</DATA></COL>
<COL><DATA>01-05-01-16</DATA></COL>
<COL><DATA>www.repubblica.it</DATA></COL></ROW>
</RESULTSET>
</FMPXMLRESULT>
启动此脚本没有出现!!!请帮帮我。我把fie piante.xml放在这个脚本的同一个文件夹中。这里是测试我的脚本的页面,如果你点击圆圈。
http://www.soluzioniwebdesign.it/provaRubini/
谢谢你
答案 0 :(得分:0)
function getName(fname, text)
{
var fname ="piante.xml";
if (window.XMLHttpRequest)
{
xhttp = new XMLHttpRequest();
}
else
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",fname,false);
xhttp.send();
xmlDoc = xhttp.responseXML;
var x=xmlDoc.getElementsByTagName("ROW");
for (var i=0;i<x.length;i++){
var y=x[i].getElementsByTagName("DATA");
if(y[1].childNodes[0].nodeValue == text){
var z= y[0].childNodes[0].nodeValue;
return z;}
}
}
这里是正确的代码......也许它可以提供帮助