我有一個XML文件,我想從該文件中查找一些值我怎麼可以這樣使用jquery搜索標籤值使用jQuery
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>ID</key>
<string>B0A6EF3C-221F-4918-89C2-340B05F6A7AD</string>
<key>Name</key>
<string>name</string>
<key>Items</key>
<array>
<dict>
<key>Mode</key>
<integer>1000</integer>
<key>background</key>
<string>RGBA:0.000000,1.000000,1.000000,1.000000</string>
<key>Enabled</key>
<true/>
</dict>
<dict>
<key>Mode</key>
<integer>1000</integer>
<key>background</key>
<string>RGBA:0.000000,1.000000,1.000000,1.000000</string>
<key>Enabled</key>
<true/>
</dict>
</array>
</dict>
</plist>
我該怎麼如果我想搜索的值,例如獲得第二<dict>
項目背景,怎麼樣使值,在這種情況下 真的,我想這樣做jQuery的
這是我嘗試到目前爲止
$.post("demo.xml",{},function(xml){
// Run the function for each dict tag inside array tag in the XML file
$('array',xml).each(function(i) {
$(this).find('dict').each(function(){
$(this).find('key').each(function(){
key = $(this).text();
value = $(this).next().text();
alert("key = " + key + " value = "+ value);
});
});
});
上面的jQuery代碼的工作很適合我,但每次返回鍵和它的價值。我想搜索特定值超出它例如
var value = $(this).find("background").value;
我想的名字,如「背景」
顯示您嘗試過的任何信息 – Hiral
您可以參考此鏈接; http://stackoverflow.com/questions/19220873/how-to-read-xml-file-contents-in-jquery-and-display-in-html-elements –
與哪些標籤? – Shin