w3pop.com :: ÍøÂçѧԺ :: XML :: XML Êý¾Ýµº
With Internet Explorer, the unofficial <xml> tag can be used to create an XML data island.
ͨ¹ýIEä¯ÀÀÆ÷£¬·ÇÕýʽµÄ<xml>±ê¼Ç¿ÉÓÃÓÚ´´½¨Ò»¸öXMLÊý¾Ýµº¡£
An XML data island is XML data embedded into an HTML page.
XMLÊý¾ÝµºÊÇǶÈëHTMLÒ³ÃæµÄXMLÊý¾Ý¡£
Here is how it works; assume we have the following XML document ("note.xml"):
½ÓÏÂÀ´½²½²ËüµÄ¹¤×÷ÔÀí¡£¼ÙÉèÎÒÃÇÓÐÏÂÃæÕâ·ÝXMLÎĵµ("note.xml")£º
<?xml version="1.0" encoding="ISO-8859-1"?> |
Then, in an HTML document, you can embed the XML file above with the <xml> tag. The id attribute of the <xml> tag defines an ID for the data island, and the src attribute points to the XML file to embed:
½Ó×Å£¬ÔÚÒ»·ÝHTMLÎĵµÀÄã¿ÉÒÔǶÈëÒ»·ÝXMLÎĵµ¡£XMLÎĵµ×î¶¥¶Ë°üº¬<xml>±êÇ©¡£<xml>±êÇ©µÄIDÊôÐÔ¶¨ÒåÁËÊý¾ÝµºµÄID£¬srcÊôÐÔÖ¸Ã÷ÁËǶÈëµÄXMLÎļþ·¾¶£º
<html> <xml id="note" src="note.xml"></xml> </body> |
However, the embedded XML data is, up to this point, not visible for the user.
È»¶ø£¬Ç¶ÈëµÄXMLÊý¾Ý¶ÔʹÓÃÕßÀ´½²ÊDz»¿É¼ûµÄ¡£
The next step is to format and display the data in the data island by binding it to HTML elements.
ÏÂÒ»²½¾ÍÊÇͨ¹ý°ÑÊý¾ÝµºµÄÊý¾Ý°ó¶¨µ½HTMLÔªËØÖÐÀ´¸ñʽ»¯Êý¾ÝÒÔ¼°ÏÔʾÊý¾Ý¡£
In the next example, we will embed an XML file called "cd_catalog.xml" into an HTML file.
ÔÚÏÂÃæÕâ¸ö°¸ÀýÖУ¬ÎÒÃǰÑÒ»·ÝÃûΪ "cd_catalog.xml" XMLÎļþǶÌ×µ½HTMLÎļþÖУº
The HTML file looks like this:
Õâ·ÝHTMLÎļþÊÇÕâÑùµÄ£º
<html> |
Example explained:
°¸Àý˵Ã÷£º
The datasrc attribute of the <table> tag binds the HTML table element to the XML data island. The datasrc attribute refers to the id attribute of the data island.
<table>±êÇ©ÖÐµÄ “datasrc” ÊôÐÔ°ÑHTML ±í¸ñ£¨table£©ÔªËذ󶨵½XMLÊý¾Ýµº¡£DatasrcÊôÐÔÖ¸µÄÊÇÊý¾ÝµºµÄIDÊôÐÔ£º
<td> tags cannot be bound to data, so we are using <span> tags. The <span> tag allows the datafld attribute to refer to the XML element to be displayed. In this case, it is datafld="ARTIST" for the <ARTIST> element and datafld="TITLE" for the <TITLE> element in the XML file. As the XML is read, additional rows are created for each <CD> element.
<td>±êÇ©²»Äܱ»°ó¶¨µ½Êý¾ÝÉÏ£¬ËùÒÔÎÒÃÇÓÃ<span>±êÇ©¡£<span>±êÇ©ÔÊÐídatafldÊôÐÔÖ¸¶¨Òª±»ÏÔʾµÄXMLÔªËØ¡£ÔÚÕâÖÖÇé¿öÏ£¬XMLÎļþÖÐµÄ datafld="ARTIST" ´ú±íÁË<ARTIST>ÔªËØ£¬datafld="TITLE" ´ú±íÁË<TITLE>ÔªËØ¡£µ±¶ÁÈ¡XMLʱ£¬Ã¿¸ö<CD>ÔªËØ¶¼»áÖØÐ»»ÐС£
If you are running IE 5.0 or higher, you can try it yourself.
Èç¹ûÄãʹÓÃIE 5.0»ò¸ü¸ß°æ±¾µÄä¯ÀÀÆ÷£¬ ÄÇô¾Í×Ô¼º¶¯ÊÖÊÔһϰɡ£
Also try this example, demonstrating <thead>, <tbody>, and <tfoot>.
Ò²¿ÉÒÔÊÔÏ Õâ¸ö°¸Àý£¬ ÑéÖ¤<thead>¡¢<tbody> ºÍ <tfoot>¡£
ÆÀÂÛ (0)
All