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>