The data described in XML can be bound to a table. The following is an example:
The HTML code is as follows:
<HTML>
<SCRIPT>...
Function Test ()
...{
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. async = "false ";
Xmldoc. Load ("cd_catalog.xml ");
VaR nodes = xmldoc.doc umentelement. selectnodes ("CD/Title"); // obtain the values of all matched (title) nodes
For (VAR I = 0; I <nodes. length; I ++)
...{
Alert (nodes [I]. Text + "");
}
// Alert (xmldoc. XML );
// Var node1_xmldoc.doc umentelement. selectsinglenode ("CD/Title"); // obtain the value of the first matched (title) node
// Alert (node. Text );
}
</SCRIPT>
<Body onload = "test ()">
<XML id = "cdcat" src = "cd_catalog.xml" tppabs = "http://www.w3schools.com/xml/cd_catalog.xml"> </XML>
<Br>
<Table border = "1" datasrc = "# cdcat">
<Thead>
<TH> artist </Th>
<TH> title </Th>
</Thead>
<Tr>
<TD>
<Span dataworks = "artist"> </span>
</TD>
<TD>
<Span dataworks = "title"> </span>
</TD>
</Tr>
</Table>
</Body>
</Html>
For the XML files used, see my article: JavaScript to implement XML navigation.
Note: Use datasrc = "# xmlid" on the table label to bind the XML file. xmlid is the ID attribute of the XML tag. The dataworks attribute can only be written in SPAN or Div (as if this is the case, readers can try to write it in other labels), in the format of dataworks = "name ", here, the name is the description of the span or Div value to be bound to the XML file (it must be consistent with a tag in the XML file ).