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>
.
.
... 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>
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>
---------- -------------------------------------------------- --------------------
Bind the data island to the or element 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: Or something like this: 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. Functionmovenext() and moveprevious() to implement navigation function. If you have With creativity, you can write very complete 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!
or <br />Title:
<span datasrc="#xmldso" datafld="TITLE"></span>
<br />Artist:
<span datasrc="#xmldso" datafld="ARTIST"></span>
<br />Year:
<span datasrc="#xmldso" datafld="YEAR"></span>
<br />Title:
<p datasrc="#xmldso" datafld="TITLE"></p>
<br />Artist:
<p datasrc="#xmldso" datafld="ARTIST"></p>
<br />Year:
<p datasrc="#xmldso" datafld="YEAR"></p>
<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>