XML
Is an ubiquitous data format in modern computers. Ajax applications are in the Web browser environment, especially the XMLHTTPRequest object, which provides good local support for processing XML. If xzmlhttprequest receives an XML content type, for example, application/XML or test/XML, it will respond to a Dom!
See the script below:
<SCRIPT>
VaR offset = 8;
Function showpopup (name, description)
{
VaR win = new datapopup (name, description, offset, offset, 320,320 );
Offset + = 32;
}
Function datapopup (name, description, X, Y, W, H)
{
VaR BOD = Document. createelement ("Div ");
Document. Body. appendchild (BOD );
This. contentdiv = Document. createelement ("Div ");
This. contentdiv. classname = "windcontents ";
This. contentdiv. innerhtml = description;
BOD. appendchild (this. contentdiv );
This. Win = new windows. Window (BOD, name, X, Y, W, H );
}
Function showinfo (Event)
{
VaR planet = This. ID;
VaR scripturl = planet + ". xml ";
New net. contentloader (scripturl, parsexml );
}
Function parsexml ()
{
VaR name = "";
VaR descrip = "";
VaR xmldoc = This. Req. responsexml;
VaR eldocroot = xmldoc. getelementsbytagname ("planet") [0];
If (eldocroot)
{
Attrs = eldocroot. attributes;
Name = attrs. getnameditem ("name"). value;
VaR ptype = attrs. getnameditem ("type"). value;
If (ptype)
{
Descrip + = "<H2>" + ptype + "</H2> ";
}
Descrip + = "<ul> ";
For (VAR I = 0; I <eldocroot. childnodes. length; I ++)
{
Elchild = eldocroot. childnodes [I];
If (elchild. nodename = "info ")
{
Descrip + = "<li>" + elchild. firstchild. Data + "</LI> \ n ";
}
}
Descrip + = "</ul> ";
}
Else {
Alert ("no document ");
}
Top. showpopup (name, descrip );
}
</SCRIPT>
The showinfo function simply opens an XMLHTTPRequest object encapsulated in the contentloader object and provides the parsexml () method as the callback. This callback function is a little more troublesome than the evalscript () method, because we need to navigate to the response Dom, extract data from it, and then manually call the showpopup () method ,! This data can be used in XML-centered applications!
A major advantage of XML is its ability to structure information! In this script, parsexml () is used to convert the functions into HTML sdks!