hi,
I am entering Australia and timz, but getting alert "sorry, no data found".
When I checked, nodes.length, it is coming length=0.
It should say "Yes, data found". Could you please check your above code.
Thanks.
Main Topics
Browse All TopicsI have a xml file like this.
<salesloc name="Australia" area="APAC">
<useralias>timz</useralias
<useralias>scott</useralia
</salesloc>
<salesloc name="italy" area="WE">
<useralias>david</useralia
<useralias>tabz</useralias
</salesloc>
I want to load this xml in javascript and wants to check for salesloc italy, useralias "david" exist or not?
ie I have javasctipt variable called salesloc and useralias. I want to check these two variables againest this xml file wheather they are exist?
Please help.
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
here is the code. I have kept the file in c:\test folder.
<html>
<head></head>
<script language="javascript">
var xmlDoc = null;
function loadIndex() {
var xmlfile = "c:\test\myxml.xml";
if (document.implementation && document.implementation.cr
xmlDoc = document.implementation.cr
xmlDoc.load(xmlfile);
} else if (window.ActiveXObject) { // MSIE uses ActiveX
xmlDoc = new ActiveXObject("Microsoft.X
xmlDoc.async = false;
xmlDoc.load(xmlfile);
}
}
function searchIndex(frm) { // search the index
var salesloc = frm.ctry.options[frm.ctry.
var useralias = frm.useralias.value;
alert(salesloc)
alert(useralias)
var xpath="sales/salesloc[@nam
var isfound = false;
alert(xpath)
if (window.ActiveXObject) {
var nodes=xmlDoc.selectNodes(x
alert(nodes.length);
isfound = (nodes.length>0);
/*
for (i=0;i<nodes.length;i++) {
document.write(nodes[i].ch
document.write("<br />");
}*/
} else if (document.implementation && document.implementation.cr
var nodes=xmlDoc.evaluate(xpat
var result=nodes.iterateNext()
isfound = (result);
/*
while(result) {
document.write(result.chil
document.write("<br />");
result=nodes.iterateNext()
}*/
}
if (!isfound) {
alert("Sorry, data not found.");
} else {
alert("Yes, data found.");
}
return false;
}
</script>
<body onLoad="loadIndex()">
<form action="" method="post" onSubmit="return searchIndex(this)">
Find:
<select name="ctry" id="ctry">
<option value="Australia">Australia
<option value="italy">italy</option>
</select>
<input name="useralias" type="text" id="useralias">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
But not getting the result.
Business Accounts
Answer for Membership
by: ryancysPosted on 2009-03-24 at 20:46:05ID: 23975903
Possible to amend the xml file to this?
<?xml version="1.0" encoding="utf-8"?>
<sales>
<salesloc name="Australia" area="APAC">
<useralias>timz</useralias>
<useralias>scott</useralias>
</salesloc>
<salesloc name="italy" area="WE">
<useralias>david</useralias>
<useralias>tabz</useralias>
</salesloc>
</sales>
then:
Select allOpen in new window