![](/img/trans.png)
[英]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.