这是我的 xml 文件:-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<results xmlns="http://gisgraphy.com">
<result>
<distance>1071.59873299109</distance>
<name>Irungattukottai</name>
<adm1Code>25</adm1Code>
<adm1Name>State of Tamil Nadu</adm1Name>
<asciiName>Irungattukottai</asciiName>
<countryCode>IN</countryCode>
<featureClass>P</featureClass>
<featureCode>PPL</featureCode>
<featureId>1269687</featureId>
<gtopo30>47</gtopo30>
<population>0</population>
<timezone>Asia/Kolkata</timezone>
<lat>12.996390342712402</lat>
<lng>79.99082946777344</lng>
<placeType>City</placeType>
<oneWay>false</oneWay>
<length>0.0</length>
<google_map_url>http://maps.google.com/maps?f=q&amp;ie=UTF-8&amp;iwloc=addr&amp;om=1&amp;z=12&amp;q=Irungattukottai&amp;ll=13.026390342712402,79.99082946777344</google_map_url>
<yahoo_map_url>http://maps.yahoo.com/broadband?mag=6&amp;mvt=m&amp;lon=79.99082946777344&amp;lat=12.996390342712402</yahoo_map_url>
<country_flag_url>/images/flags/IN.png</country_flag_url>
</result>
<result>
<distance>1892.33578431928</distance>
<name>Valapuram</name>
<adm1Code>25</adm1Code>
<adm1Name>State of Tamil Nadu</adm1Name>
<asciiName>Valapuram</asciiName>
<countryCode>IN</countryCode>
<featureClass>P</featureClass>
<featureCode>PPL</featureCode>
<featureId>1466104</featureId>
<gtopo30>33</gtopo30>
<population>0</population>
<timezone>Asia/Kolkata</timezone>
<lat>13.016940116882324</lat>
<lng>80.00167083740234</lng>
<placeType>City</placeType>
<oneWay>false</oneWay>
<length>0.0</length>
<google_map_url>http://maps.google.com/maps?f=q&amp;ie=UTF-8&amp;iwloc=addr&amp;om=1&amp;z=12&amp;q=Valapuram&amp;ll=13.046940116882324,80.00167083740234</google_map_url>
<yahoo_map_url>http://maps.yahoo.com/broadband?mag=6&amp;mvt=m&amp;lon=80.00167083740234&amp;lat=13.016940116882324</yahoo_map_url>
<country_flag_url>/images/flags/IN.png</country_flag_url>
</result>
</results>
这是我的完整代码:-
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var xml;
$.get(
"search.xml",
null,
function (data) {
xml = data;
},
"xml"
);
function get_list(ls) {
var elName = $('#select').val();
var value = $('#value').val();
if(elName == "" || value == "")
{
}
else if (elName != "" || value != "")
{
//var xPath = '//loction[ @lat '+ ls +' "'+elName+'" and @lng '+ ls +' "'+value+'"][1]/preceding-sibling::*/@*';
var xPath = '//result[lat='+elName+' and lng='+value+']/node()/text()';
//var xPathh = '//lng[@lng '+ ls +' "'+ value +'"]'+'/../City/@value';
var iterator = xml.evaluate(xPath, xml.documentElement, null,
XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var thisNode = iterator.iterateNext();
var str = '';
while (thisNode) {
if (str) {
str += ', ';
}
str += thisNode.textContent;
thisNode = iterator.iterateNext();
}
$("#result").text(str);
}
else
{}
}
</script>
</head>
<body>
<input type="text" id="select">
<input type="text" id="value">
<input type="button" name="button" value="Search" onclick="get_list('=')">
<div id="result">
</div>
</body>
</html>
i want:-
如果在我的 xml 文件中两者都匹配,我想在文本框中输入纬度和经度值,然后返回兄弟节点值。
problem:-
我不知道如果根元素有一个
像<results xmlns="http://gisgraphy.com">
它这样的
属性值如果删除这个属性值然后工作完美的话会有什么问题......
任何想法它的食物对我有帮助......
谢谢