Sample code sharing for xml applications

黄舟
Release: 2017-03-29 15:49:10
Original
1770 people have browsed it

This section demonstrates a small XMLapplicationframework.

-------------------------------------------------- ------------------------------------

Start with XML document
First We create a simple XML document.

Let’s take a look at our original XML document describing the CD directory.

<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
Copy after login

.
.
... more ...
.

------------------ -------------------------------------------------- ------------

Load XML documents into the data island
The data island can access XML files.

Through data island, XML documents can be introduced into HTML pages.

<xml src="cd_catalog.xml" id="xmldso" async="false">
</xml>
Copy after login

Using the above example code, you can load the cd_catalog.xml file into a data island called "xmldso". AttributeThe role of async="false" is to ensure that all data in the XML document is loaded into memory before the HTML processor starts processing the XML data.

-------------------------------------------------- ------------------------------------

Bind XML data To the table element of HTML
The table element in HTML can be used to display XML data.

In order for your XML data to be displayed in an HTML page, the data island must be bound to an HTML element.

To bind XML data to a table element, you need to add a resource attribute to the table attribute and add a field attribute to the span element:

<table datasrc="#xmldso" width="100%" border="1">
<thead>
<th>Title</th>
<th>Artist</th>
<th>Year</th>
</thead>
<tr align="left">
<td><span datafld="TITLE"></span></td>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="YEAR"></span></td>
</tr></table>
Copy after login

---------- -------------------------------------------------- --------------------

Bind the data island to the or

element
or

elements can be used to display XML data.

There is no need to use table elements to display XML data. Data can be bound to any HTML element through data islands.

All you have to do is add some or

elements to your page, and use the data resource attribute to bind each element to the XML document element, like this:

<br />Title:
<span datasrc="#xmldso" datafld="TITLE"></span>
<br />Artist:
<span datasrc="#xmldso" datafld="ARTIST"></span>
<br />Year:
<span datasrc="#xmldso" datafld="YEAR"></span>
Copy after login

Or something like this:

<br />Title:
<p datasrc="#xmldso" datafld="TITLE"></p>
<br />Artist:
<p datasrc="#xmldso" datafld="ARTIST"></p>
<br />Year:
<p datasrc="#xmldso" datafld="YEAR"></p>
Copy after login

Note that if you use the

element, the data will be displayed on a new line.

In the above example, you can see that the XML data is displayed in one line. If you want to control data wrapping, you must add some scripts to your code.

-------------------------------------------------- ------------------------------------

Add ## to your XML data #NavigationScriptNavigation function can be realized through script program.

Add data island method and use script

Functionmovenext() and moveprevious() to implement navigation function.

<script type="text/javascript">
function movenext()
{
x=xmldso.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}
}
function moveprevious()
{
x=xmldso.recordset
if (x.absoluteposition > 1)
{
x.moveprevious()
}
}
</script>
Copy after login
--------------------------------------------- -------------------------------------

Summary

If you have With creativity, you can write very complete applications.

If you use the knowledge you have learned on this page and use your imagination, you can easily create perfect applications.

The above is the detailed content of Sample code sharing for xml applications. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!