XML Easy Learning Manual (6)

Source: Internet
Author: User
Xml

Step three: Create the corresponding HTML file.
1. Import XML data.
We know that in the current popular browsers, only Microsoft's IE5.0 version of the browser supports XML for the time being. IE supports inserting XML by object object in HTML, and imports data through the XmlDocument.Load () method of JS. We look at the code: <object width= "0" height= "0"
Classid= "clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" id= "Xmldso" >
</object>

Defines a object,id named Xmldso. Then use JS in the head area to introduce XML data:

<script for= "window" event= "onload" >
Xmldso. XmlDocument.Load ("Cd.xml");
</script>

2. Bundle of data.
The XML data is then bound to the table using the <SPAN> identity. Where id,datasrc,dtatfld are the properties of <SPAN>. The code is as follows:

<table>
<tr><td>title:</td><td><span id= "title" datasrc= #xmldso datafld= "title" ></span ></td></tr>
<tr><td>artist:</td><td><span id= "Artist" datasrc= #xmldso datafld= "Artist" ></ Span></td></tr>
<tr><td>year:</td><td><span id= "Year" datasrc= #xmldso datafld= "year" ></SPAN> </td></tr>
<tr><td>country:</td><td><span id= "Country" datasrc= #xmldso datafld= "Country" ></ Span></td></tr>
<tr><td>company:</td><td><span id= "Company" Datasrc= #xmldso datafld= "Company" ></ Span></td></tr>
<tr><td>price:</td><td><span id= "Price" datasrc= #xmldso datafld= ' price ' ></span ></td></tr>
</table>

3. Action operation.
Finally, provide the browse button for the data:
<input Type=button value= "Previous CD" >
<input Type=button value= "Next CD" >

and use JS to complete the two mouse clicks: MoveNext () and MovePrevious (). Add the following code to the head area:

<script language= "JavaScript" >
function MoveNext ()
{
if (Xmldso.recordset.absoluteposition < Xmldso.recordset.recordcount)
{
Xmldso.recordset.movenext ();
}
}
function MovePrevious ()
{
if (Xmldso.recordset.absoluteposition > 1)
{
Xmldso.recordset.moveprevious ();
}
}
</script>

OK, let's look at all the original code for the HTML file:


<script for= "window" event= "onload" >
Xmldso. XmlDocument.Load ("Cd.xml");
</script>

<script language= "JavaScript" >
function MoveNext ()
{
if (Xmldso.recordset.absoluteposition < Xmldso.recordset.recordcount)
{
Xmldso.recordset.movenext ();
}
}
function MovePrevious ()
{
if (Xmldso.recordset.absoluteposition > 1)
{
Xmldso.recordset.moveprevious ();
}
}
</script>

&LT;TITLE&GT;CD navigate</title>

<body>
<p>
<object width= "0" height= "0"
Classid= "clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" id= "Xmldso" >
</object>

<table>
<tr><td>title:</td><td><span id= "title" datasrc= #xmldso datafld= "title" ></span ></td></tr>
<tr><td>artist:</td><td><span id= "Artist" datasrc= #xmldso datafld= "Artist" ></ Span></td></tr>
<tr><td>year:</td><td><span id= "Year" datasrc= #xmldso datafld= "year" ></SPAN> </td></tr>
<tr><td>country:</td><td><span id= "Country" datasrc= #xmldso datafld= "Country" ></ Span></td></tr>
<tr><td>company:</td><td><span id= "Company" Datasrc= #xmldso datafld= "Company" ></ Span></td></tr>
<tr><td>price:</td><td><span id= "Price" datasrc= #xmldso datafld= ' price ' ></span ></td></tr>
</table>

<p>
<input Type=button value= "Previous CD" >
<input Type=button value= "Next CD" >
</p>

</body>

Save the above code as a cd.htm file and put it together in the second step of the Cd.xml file. Open the Cd.htm file and you'll see the same effect as the example above.



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.