this is xml file(demo.xml):-
<products> <product_id value="1"> <tab_id value="351"> <tab_name value="test1"/> <dist_map value="5"/> </tab_id> </product_id> <product_id value="2"> <tab_id value="352"> <tab_name value="test2"/> <dist_map value="3"/> </tab_id> </product_id> </products>
this is code:-
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> var xml; $.get( "demo.xml", null, function (data) { xml = data; }, "xml" ); function get_node(ls) { var elName = $('#select').val(); var value = $('#value').val(); var xPath = '//*[(text() = '+elName+') or @value '+ ls +' '+value+']'+'/../../@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="select"> <input type="text" id="value"> <input type="button" name="button" value="Less than" onclick="get_node('<')"></input> <input type="button" name="button" value="Grater than" onclick="get_node('>')"></input> <input type="button" name="button" value="Equal" onclick="get_node('=')"></input> <div id="result"> </div> </body> </html>
I um using this xpath:-
var xPath = '//*[(text() = '+elName+') or @value '+ ls +' '+value+']'+'/../../@value';
with help of this code... its work fine
if i enter dist_map
in first textbox and
in second textbox there attibute value
as per operator gives perfact o/p as i need...
but if my xml is look like this :-
<products> <product_id value="1"> <tab_id value="351"> <tab_name value="test1"/> <dist_map value="5,8,9"/> </tab_id> </product_id> <product_id value="2"> <tab_id value="352"> <tab_name value="test2"/> <dist_map value="3,7,9"/> </tab_id> </product_id> </products>
in this xml file
i have multiple attribute value of dist_map
like 3,8,9
whats xpath set for this
if i have enter any one value of them then its work as my working o/p...
thanks...