At the beginning, I only knew how to access. Do or. jsp through Ajax. Today I saw the access to the XML file.
VaR url = "myxml. xml"; // The URL points to the XML file path.
Createxmlhttprequest ();
Xmlhttpreq. onreadystatechange = processresponse;
Xmlhttpreq. Open ("get", URL, true );
Xmlhttpreq. Send (null );
XML file format:
<? XML version = "1.0" encoding = "gb2312"?>
<Classmates>
<Student>
<Sid> 1 </Sid>
<Sname> reqe </sname>
<GRE> 1700 </GRE>
<Tse> 120 </TSE>
</Student>
<Student>
<Sid> 2 </Sid>
<Sname> rqerwe </sname>
<GRE> 1800 </GRE>
<Tse> 120 </TSE>
</Student>
<Student>
<Sid> 3 </Sid>
<Sname> iuir </sname>
<GRE> 1700 </GRE>
<Tse> 120 </TSE>
</Student>
</Classmates>
Resolution:
VaR students = xmlhttpreq. responsexml. getelementsbytagname ("student"); // you can obtain an array of all student nodes.
For (VAR I = 0; I <students. length; I ++)
{
VaR stud = students [I]; // Get a stutdent Node
VaR name = stud. getelementsbytagname ("sname") [0]. firstchild. Data; // obtain the data in the node.
VaR GRE = stud. getelementsbytagname ("GRE") [0]. firstchild. Data;
VaR Tse = stud. getelementsbytagname ("Tse") [0]. firstchild. Data;
}