Bind XML data to Table

Source: Internet
Author: User

Simple XML data binding example:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "zh-cn">
<Title> Binding xml data </title>
<Head>
<Script type = "text/javascript" language = "javascript">
Function init ()
{
// Initialize the total number of pages on the page
Var totPage = document. getElementById ('Total ');
TotPage. innerText = data. recordset. recordcount;
}

Function page (databox, datasrc, moveto)
{
/*
Function parameter: databox is the container id. In this example, table datasrc with the id of oTab is the data source id,
In this example, data moveto is paging: firstPage (homepage) | previousPage (Previous Page) | nextPage (next page) | lastPage (last page)
*/
Var curPage = document. getElementById ('current ');
Switch (moveto)
{
Case 'firstpage ':
Databox. firstPage (); datasrc. recordset. movefirst (); break;
Case 'lastpage ':
Databox. lastPage (); datasrc. recordset. movelast (); break;
Case 'previouspage ':
If (datasrc. recordset. absoluteposition> 1)
{
Databox. previousPage ();
Datasrc. recordset. moveprevious ();
}
Break;
Case 'nextpage ':
If (datasrc. recordset. absoluteposition <datasrc. recordset. recordcount)
{
Databox. nextPage ();
Datasrc. recordset. movenext ();
}
Break;
}
CurPage. innerText = datasrc. recordset. absoluteposition; // display the current page number
}
</Script>

</Head>

<Body onload = "init ();">
<! -- Internal data source instance -->
<! -- If the content is large, it can be stored in the test. xml file separately, and then imported using <xml src = "test. xml"> </xml> -->
<! -- <Xml id = "data" src = "test. xml"> </xml> <-->

<Xml id = "data">
<Root>
<Article>
<Title> first page </title>
<Content> 1111111111111111 </content>
</Article>
<Article>
<Title> second page </title>
<Content> 2222222222222222 </content>
</Article>
<Article>
<Title> page 3 </title>
<Content> 3333333333333333 </content>
</Article>
<Article>
<Title> page 4 </title>
<Content> 4444444444444444 </content>
</Article>
<Article>
<Title> page 5 </title>
<Content> 55555555555 </content>
</Article>
</Root>
</Xml>

<Table datasrc = "# data" dataPageSize = "1" id = "oTab" border = "1">
<Tr>
<Td> title: </td>
<Td> <span dataworks = "title"/> </td>
</Tr>
<Tr>
<Td> content: </td>
<Td valign = "top"> <span dataworks = "content"/> </td>
</Tr>
</Table>
<Div>
<Input type = "button" value = "first page" onclick = "page (oTab, data, 'firstpage');"/>
<Input type = "button" value = "Previous page" onclick = "page (oTab, data, 'previouspage');"/>
<Input type = "button" value = "next page" onclick = "page (oTab, data, 'nextpage');"/>
<Input type = "button" value = "last page" onclick = "page (oTab, data, 'lastpage');"/>
<Br/> page <span id = "current"> 1 </span> | total pages of <span id = "total"> </span> & nbsp;
</Div>
</Body>
</Html>

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.