无法获取XML中的节点值,如何获取
Cant get node value in XML, how can I get it?
我目前使用w3cschools上的一个简单的循环XML脚本,效果很好:
if (p1p2total == 5)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","xml/SearchRequest-12437.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("item");
for (i=0;i<x.length;i++)
{
document.write("<tr><td class='c3c1'>");
document.write(x[i].getElementsByTagName("key")[0].childNodes[0].nodeValue);
document.write("</td><td class='c3c2b'>");
document.write(x[i].getElementsByTagName("priority")[0].childNodes[0].nodeValue);
document.write("</td><td class='c3c3b'>");
document.write(x[i].getElementsByTagName("customfields")[0].getElementsByTagName("customfield")
[0].getAttributeNode("id").textContent);
document.write("</td></tr>");
}
}
然而,在我的第三个节点值查询customfields中,我试图获得xml中具有以下路径的节点的textContent:
项目->自定义字段->自定义字段id=10080->自定义字段值
如何获取customfieldwalue的textContent值?父节点必须具有id=10080的属性,因为不同的项具有不同数量的customfield标记,这些标记具有不同的子节点id。
请帮忙!!!
我只需要这个在火狐工作。。。
---编辑---
好的,所以我发现我需要使用的xpath是:
./customfields/customfield[@id='customfield_10080']/customfieldvalues/customfieldvalue/text()
那么我该如何更换
document.write(x[i].getElementsByTagName("customfields")[0].getElementsByTagName("customfield")[0].getAttributeNode("id").textContent);
以提取我提供的Xpath的文本内容,同时保留在javascript循环中?我需要这个来为每个
就我而言,你只需要打电话给
document.write(x[i].getElementsByTagName("customfields")[0].getElementsByTagName("customfield").text;
试试看。有几种方法可以从javascript中读取和解析XML。我不会推荐w3schools学习。转到根目录,下次尝试MDN;)
我希望它能帮助
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 使用Javascript获取所选选项ID
- 在jQuery中获取表的行索引
- 使用jquery将mysql数据获取到新的表行中
- 在动态创建的元素上获取对特定选择器的引用
- 从城市名称获取惊喜
- Angular只从数组中获取所需的数据
- 无法将数据从firebase获取到我的html页面
- 从ajax请求中获取javascript对象
- Jquery,文本区域换行.don't获取 并获取↵.
- 获取Ajax获取的图像的宽度
- 当集合是惰性加载时,如何获取已获取的模型
- jQuery.获取-如何获取文本而不是html
- 如何获取'获取'属性
- PhantomJS页面使用嵌套循环获取以获取新页面
- 使用PHP获取javascript获取的值