this is my xml document:-
<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>
</root>
this is my javascript html code:-
<html>
<head>
<script src=".8.3/jquery.min.js"></script>
<script>
var xml;
var ind_sex;
$.get(
"code.xml",
null,
function (data) {
xml = data;
},
"xml"
);
function get_list() {
var city = $('#name').val();
alert(city);
var xPath = '//*[@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);
}
</script>
</head>
<body>
<input type="text" id="name"></input>
<input type="button" name="button" value="Search" onclick="get_list()">
<div id="result">
</div>
</body>
</html>
here i am try to input in textbox city name if its match on my xml file then its return me there country name.
i dont get any error but not getting result.
i think problem in my xPath pleasae help me out of this.
this is my xml document:-
<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>
</root>
this is my javascript html code:-
<html>
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var xml;
var ind_sex;
$.get(
"code.xml",
null,
function (data) {
xml = data;
},
"xml"
);
function get_list() {
var city = $('#name').val();
alert(city);
var xPath = '//*[@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);
}
</script>
</head>
<body>
<input type="text" id="name"></input>
<input type="button" name="button" value="Search" onclick="get_list()">
<div id="result">
</div>
</body>
</html>
here i am try to input in textbox city name if its match on my xml file then its return me there country name.
i dont get any error but not getting result.
i think problem in my xPath pleasae help me out of this.
- 2 You apparently replaced your question with something pletely different after someone tried answering it. Why not just start a new question? – Barmar Commented Apr 21, 2013 at 6:03
- I pletely agree with @Barmar. It is not remendable to pletely change the question just on the day before the deadline. Please, ask a new question, if you have a new problem. – Dimitre Novatchev Commented Apr 26, 2013 at 4:30
2 Answers
Reset to default 7 +50Use:
var xPath = '//*[@value = "' + city + '"]/../../@value';
An equivalent expression is:
var xPath = '//*[*/*[@value = "' + city + ']]/@value';
As far as I remember, lists don't work like that... they're variables associated with a given value, so it's more like:
list($a, $b, $c) = [1, 2, 3];
Anyway, why don't you take a look at the 'Lists' section in the phpredis page? It's one of the remended PHP clients for Redis, and its examples are quite clear
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745543420a4632231.html
评论列表(0条)