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

w3pop.com :: ÍøÂçѧԺ :: XLink/XPointer :: XLink ʵÀý

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

XLink/XPointer
XLink½éÉÜ
Xlink/Xpointer Ó..
XLink ʵÀý
XPointer ʵÀý
Xlink ÕªÒª
XLink ²Î¿¼

XLink ʵÀý


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

Let's try to learn some basic XLink syntax by looking at an example.
ÏÖÔÚ¾ÍÈÃÎÒÃÇͨ¹ýÒ»¸ö°¸ÀýÀ´Ñ§Ï°Ò»ÏÂXLinkµÄ»ù±¾Óï·¨¡£


The XML Example Document
XML °¸ÀýÎĵµ

Look at the following XML document, "bookstore.xml", that represents a few books:
Çë¿´ÏÂÃæÕâ¸öÃûΪ "bookstore.xml"µÄXMLÎĵµ£¬Ëü±íʾһС²¿·ÖÊé¼®£º

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">

<description
xlink:type="simple"
xlink:href="http://book.com/images/HPotter.gif"
xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
<book title="XQuery Kick Start">
<description
xlink:type="simple"
xlink:href="http://book.com/images/XQuery.gif"
xlink:show="new">
XQuery Kick Start delivers a concise introduction
to the XQuery standard.......
</description>

</book>
</bookstore>

View the "bookstore.xml" file in your browser
ÔÚä¯ÀÀÆ÷Öв鿴"bookstore.xml"Îļþ

In the example above the XLink namespace is declared at the top of the document (xmlns:xlink="http://www.w3.org/1999/xlink"). This means that the document has access to the XLink attributes and features.
ÔÚÉÏÊö°¸ÀýÖУ¬XLinkÃüÃû¿Õ¼äÔÚÎļþµÄ×î¶¥¶ËÉùÃ÷µÄ(xmlns:xlink="http://www.w3.org/1999/xlink")¡£Õâ¾ÍÒâζןÃÎĵµ¿ÉÒÔʹÓÃXLinkÊôÐÔºÍÌØÐÔ¡£

The xlink:type="simple" creates a simple "HTML-like" link. You can also specify more complex links (multidirectional links), but for now, we will only use simple links.
xlink:type="simple" ´´½¨ÁËÒ»¸ö¼òµ¥ "HTML-like" Á´½Ó£¬ÄãÒ²¿ÉÒÔÖ¸¶¨¸ü¶àµÄ¸´ÔÓÁ´½Ó£¨¶à·½ÏòÁ´½Ó£©¡£µ«ÊÇ£¬Ä¿Ç°ÎÒÃÇÖ»»áʹÓüòµ¥µÄÁ´½Ó¡£

The xlink:href attribute specifies the URL to link to, and the xlink:show attribute specifies where to open the link. xlink:show="new" means that the link (in this case, an image) should open in a new window.
xlink:href ÊôÐÔÏêϸָÃ÷ÁËÐèÒªÁ´½ÓµÄURI£¬xlink:show ÊôÐÔÏêϸָÃ÷ÁËÁ´½Ó´ò¿ªµÄ¾ßÌ巽λ¡£xlink:show="new" ÏêϸָÃ÷ÁËÁ´½Ó£¨±ÈÈ磺һ¸öͼÏñ£©ÊÇ·ñÐèÒªÔÚÒ»¸öеĴ°¿ÚÖдò¿ª¡£


XLink - Going Further
XLink——×ߵøüÉîÔ¶

In the example above we have only demonstrated simple links. XLink is getting more interesting when we want to access remote locations as resources, instead of standalone pages. The <description> element in the example above sets the value of the xlink:show attribute to "new". This means that the link should open in a new window. We could have set the value of the xlink:show attribute to "embed". This means that the resource should be processed inline within the page. When you consider that this could be another XML document and not just an image, you could, for example, build a hierarchy of XML documents.
ÔÚÉÏÊö°¸ÀýÖУ¬ÎÒÃÇÖ»Àý¾ÙÁËÒ»¸ö¼òµ¥µÄÁ´½Ó°¸Àý¡£µ±ÄãÏ£Íû·ÃÎÊÔ¶³ÌµØÖ·×÷ΪÁ´½Ó×ÊԴʱ£¬XLink¾Í»á±äµÃ¸ü¼ÓÓÐЧ¡£ÔÚÉÏÊö°¸ÀýÖУ¬<description> ÔªËØ½«“xlink:show”µÄÊôÐÔÖµÉèÖÃΪ“new”£¬ÕâÒâζ×ÅÁ´½Ó»áÔÚÒ»¸öеĴ°¿ÚÖдò¿ª£»ÎÒÃÇ¿ÉÒÔ½«“xlink:show”µÄÊôÐÔÖµÉèÖÃΪ "embed"£¬Ê¹ÕâЩ×ÊÔ´ÔÚÒ³ÃæÄÚ²¿ÖðÐд¦Àí¡£ÔÙ±ÈÈ磬µ±Äã¾õµÃÕâÊÇÁíÍâÒ»¸öXMLÎĵµ¶ø²»½ö½öÊÇÒ»ÕÅͼƬʱ£¬ÄÇô£¬Äã¿ÉÒÔ´´½¨Ò»¸öXML²ã´ÎÎĵµ¡£

With XLink, you can also specify WHEN the resource should appear. This is handled by the xlink:actuate attribute. xlink:actuate="onLoad" specifies that the resource should be loaded and shown when the document loads. However, xlink:actuate="onRequest" means that the resource is not read or shown before the link is clicked. This is very handy for low-bandwidth settings.
ͨ¹ýXLink£¬ÄãÒ²¿ÉÒÔÖ¸¶¨×ÊÔ´³öÏÖµÄʱ¼ä¡£Õâ¿ÉÒÔʹÓà xlink:actuate ÊôÐÔÀ´´¦Àí¡£xlink:actuate="onLoad" ¾ßÌåÖ¸¶¨ÁË£ºµ±Îļþ±»¼ÓÔØÊ±£¬×ÊÔ´Ò²ÐèÒª±»¼ÓÔØ²¢ÏÔʾ¡£È»¶ø£¬xlink:actuate="onRequest" Òâζ×Å£ºÔÚÁ´½Ó±»µã»÷֮ǰ£¬²»ÔÊÐíÔĶÁ»òÏÔʾ×ÊÔ´¡£Õâ¶ÔÕ­´ø£¨´ø¿íºÜСµÄÍøÂç»·¾³£©ÅäÖÃÀ´Ëµ£¬ÊǷdz£ÊµÓõġ£

ÆÀÂÛ (0) All