这是我的代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var xml;
$.get(
"code.xml",
function(data) { xml=data; },
"html"
);
function get_list(){
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find('[value="'+$('#select').val()+'"]');
$nodes = $title.find('*');
var result='';
$nodes.each(function(){
result += $(this).attr('value');
result += ' ';
});
$("#result").html(result);
}
</script>
</head>
<input type="text" id="select">
<input type="button" name="button" value="Search" onclick="get_list()" >
<div id="result">
</div>
</html>
这是我的xml
文件:
<root>
<child_1 entity_id = "1" value="india">
<child_2 entity_id = "2" value="gujarat">
<child_3 entity_id = "3" value="Ahemdabad"/>
<child_4 entity_id = "4" value="Surat"/>
<child_5 entity_id = "5" value="Rajkot"/>
</child_2>
</child_1>
<child_6 entity_id = "6" value="Rasia">
<child_7 entity_id = "7" value="state">
<child_8 entity_id = "8" value="cty"/>
<child_9 entity_id = "9" value="cty1"/>
<child_10 entity_id = "10" value="cty2"/>
</child_2>
</child_6>
</root>
有了这段代码,我得到了
child node value
.
我想要一些东西,比如当我输入textbox
任何城市名称时:Ahemdabad、Surat、Rajkot;country name
然后它在我的 xml 文件上的匹配会像India一样返回我。
谢谢!