javascript - get parent element attribute value -


this 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 javascript html code:-

<html> <head>     <script src="http://ajax.googleapis.com/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 try input in textbox city name if match on xml file return me there country name.
dont error not getting result.
think problem in xpath pleasae me out of this.

use:

var xpath = '//*[@value = "' + city + '"]/../../@value'; 

an equivalent expression is:

var xpath = '//*[*/*[@value = "' + city +  ']]/@value'; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -