ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: XML :: XML Êý¾Ýµº

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

XML
XML DHTMLÐÐΪ
XML Ïà¹Ø¼¼Êõ
XML ±à¼­Æ÷
XML ÕªÒª
XML ʵÀý
XML×Ö·û±àÂë
xml ÎĵµÊ÷
IEºÍ»ðºü¶ÁÈ¡XML·..

XML Êý¾Ýµº


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-10 ä¯ÀÀ:6164 :: ::

With Internet Explorer, the unofficial <xml> tag can be used to create an XML data island.
ͨ¹ýIEä¯ÀÀÆ÷£¬·ÇÕýʽµÄ<xml>±ê¼Ç¿ÉÓÃÓÚ´´½¨Ò»¸öXMLÊý¾Ýµº¡£


XML Data Embedded in HTML
ǶÈëHTMLµÄ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"?>

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>
</note>

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>
<body>
<xml id="note" src="note.xml"></xml>
</body>
</html>

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ÔªËØÖÐÀ´¸ñʽ»¯Êý¾ÝÒÔ¼°ÏÔʾÊý¾Ý¡£


Bind Data Island 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ÎļþÖУº

²é¿´"cd_catalog.xml".

The HTML file looks like this:
Õâ·ÝHTMLÎļþÊÇÕâÑùµÄ£º

<html>

<body>

<xml id="cdcat" src="cd_catalog.xml"></xml>

<table border="1" datasrc="#cdcat">

<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>

</body>
</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