how to take child element from xml file using javascript

Posted by Klbaiju under JavaScript on 1/11/2013 | Points: 10 | Views : 1065 | Status : [Member] | Replies : 0
hi,
iam doing autocomplete in my application using javascript.

i got one example
this is xml file

<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Emp id="1000" name="Arrjun" />
<Emp id="1013" name="aji" />
<Emp id="1014" name="biji" />
<Emp id="1015" name="arjun" />
<Emp id="1016" name="sarin" />
<Emp id="1017" name="biju" />
<Emp id="1018" name="dini" />
</Employees>

this is the code
xmlDoc1=document.implementation.createDocument("", "doc", null)
xmlDoc1.async=false;
xmlDoc1.load("Employee.xml");

var noOfCompanyTags = xmlDoc1.getElementsByTagName("Employees");


var userdetails = noOfCompanyTags[0].getElementsByTagName("Emp");


for(var num1=0;num1< userdetails.length ;num1++)
{


YAHOO.example.statesArray[num1]=userdetails[num1].getAttribute("name");


}
this is working fine.
the problem is in my application
xml file is like this
<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Emp>
<id>100</id>
<name>arun</name>
</Emp>
<Emp>
<id>110</id>
<name>arjun</name>
</Emp>
<Employees>
I want to take name
how to change the above code as per second xml file.
Regards
BAIJU




Responses

(No response found.)

Login to post response