Bind XML to table

Source: Internet
Author: User

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.