[英]Get an attribute from an element in a xml file which is called by random in javascript
[英]root element attribute of xml file to be extracted using javascript
如何从XML文件URL获取根元素属性并作为引导表数据传递?
必须使用JavaScript来完成上述任务。 URl: http://xxxxxx/y.xml
例如:
<xxx-yyyyy zzzzzzz="2016-11-03T06:34:59+02:00">
我想在此根元素中获取日期。
请帮忙
$(yourXML)
将其转换为jquery对象,这就像处理DOM对象一样简单。 .attr()
函数读取属性。 下面是示例代码,(这里是一个小提琴 ,演示了如何在jquery中使用xml数据)
$(function(){ // alternate syntax for $(document).ready(function(){..
$.ajax({
type: "GET" ,
url: "http://xxxxxx/y.xml" ,
dataType: "xml" , // make sure to set the dataType to xml
success: function(xml) {
var xmlDoc = $.parseXML(xml); //Parse the givn XML
var $xml = $(xmlDoc); // convert XML into jquery object
var creationDate = $xml.find("ris-metadata").attr('creation');
alert(creationDate); // this will give you the required data.
// this will update the second column data of the first row.
$('#yourTableId tbody td:eq(1)').text(creationDate);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.