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

w3pop.com :: ÍøÂçѧԺ :: XLink/XPointer :: Xlink/Xpointer Óï·¨

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

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

Xlink/Xpointer Óï·¨


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

XLink Syntax
XLink Óï·¨

In HTML, we know (and all the browsers know!) that the <a> element defines a hyperlink. However, this is not how it works with XML. In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what hyperlink elements will be called in XML documents.
ÔÚHTMLÖУ¬ÎÒÃÇÖªµÀ£¨²¢ÇÒ£¬ËùÓÐä¯ÀÀÆ÷¶¼ÖªµÀ£¡£©£¬<a>ÔªËØ¶¨ÒåÁËÒ»¸ö³¬Á´½Ó¡£È»¶ø£¬ÔÚXMLÖв¢²»ÊÇÕâÑùµÄ¡£ÔÚXMLÎļþÖУ¬Äã¿ÉÒÔʹÓÃÈκÎÒ»¸öÄãËùÉèÏëµÄÔªËØÃû³Æ——Òò´Ë£¬ÈÃä¯ÀÀÆ÷Ô¤ÖªXMLÎļþÖÐÄܱ»·ÃÎʵij¬Á´½ÓÔªËØÊDz»¿ÉÄܵġ£

The solution for creating links in XML documents was to put a marker on elements that should act as hyperlinks.
ÔÚXMLÎļþÖд´½¨Á´½ÓµÄ¾ßÌå·½·¨ÊÇ£ºÎªÐèÒªÖ´Ðг¬Á´½Ó×÷ÓõÄÔªËØ¼ÓÈëÒ»¸ö±ê¼Ç¡£

Below is a simple example of how to use XLink to create links in an XML document:
ÏÂÃæÁоÙÁËÈçºÎÔÚXMLÎĵµÖÐʹÓÃXLink´´½¨Á´½ÓµÄ¼òÒ×°¸Àý£º

<?xml version="1.0"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"

xlink:href="http://www.w3schools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>

To get access to the XLink attributes and features we must declare the XLink namespace at the top of the document.
Èç¹ûÄãÏ£ÍûʹÓÃXLinkÊôÐÔºÍÌØÐÔ£¬ÄǾͱØÐëÔÚÎļþ¶¥²¿ÉùÃ÷XLinkµÄÃüÃû¿Õ¼ä¡£

The XLink namespace is: http://www.w3.org/1999/xlink.
XLinkÃüÃû¿Õ¼äÊÇ£ºhttp://www.w3.org/1999/xlink¡£

The xlink:type and the xlink:href attributes in the <homepage> elements define that the type and href attributes come from the xlink namespace.
<homepage> ÔªËØÖÐµÄ “xlink:type” ÊôÐÔºÍ “xlink:href” ÊôÐÔ¶¨ÒåÁËÀ´×ÔÓÚXLinkÃüÃû¿Õ¼äµÄÀàÐͺÍhrefÊôÐÔ¡£

The xlink:type="simple" creates a simple, two-ended link (means "click from here to go there"). We will look at multi-ended (multidirectional) links later.
xlink:type="simple" ´´½¨ÁËÒ»¸ö¼òµ¥µÄ“Ë«±ßÁ´½Ó”£¨“Ë«±ßÁ´½Ó”µÄÒâ˼ÊÇ"´ÓÕâ¶ùµã»÷µ½ÄǶù"£©¡£ÔÚºóÃæµÄÄÚÈÝÖУ¬ÎÒÃÇ»áѧϰ“¶à±ßÁ¬½Ó”¡£


XPointer Syntax
XPointer Óï·¨

In HTML, we can create a hyperlink that either points to an HTML page or to a bookmark inside an HTML page (using #).
ÔÚHTMLÖУ¬ÎÒÃÇ¿ÉÒÔ´´½¨Ò»¸öÈÎÒâÖ¸ÏòHTMLÒ³Ãæ»òHTMLÒ³ÃæÄÚµÄÊéÇ©³¬Á´½Ó£¨ÊéÇ©³¬Á´½ÓʹÓÃ#£©¡£

Sometimes it is more useful to point to more specific content. For example, let's say that we want to link to the third item in a particular list, or to the second sentence of the fifth paragraph. This is easy with XPointer.
ÓÐʱ£¬Ö¸Ïò¾«È·µÄÄÚÈÝ»áÏԵøü¼ÓÓÐЧ¡£±ÈÈ磬µ±ÎÒÃÇÐèÒªÔÚÒ»ÕÅÌØ¶¨µÄÁбíÀïÁ´½ÓµÚÈýÏî»òÁ´½Óµ½µÚÎå¶ÎµÄµÚ¶þ¾ä»°Ê±£¬Ê¹Óà XPointer ¾Í»áʹÕû¸ö¹ý³ÌµÄʵÏÖ±äµÃ·Ç³£¼òµ¥¡£

If the hyperlink points to an XML document, we can add an XPointer part after the URL in the xlink:href attribute, to navigate (with an XPath expression) to a specific place in the document.
Èç¹û³¬Á´½ÓÖ¸ÏòXMLÎĵµ£¬ÎÒÃÇ¿ÉÒÔÔÚ“XLink:href”ÊôÐÔÖеÄURIÖ®ºóÌí¼ÓÒ»¸öXPointer²¿·Ö£¬´Ó¶øÍ¨¹ýʹÓÃXPath±í´ïʽʹÆä¶¨Î»µ½ÎĵµÖеľßÌ嵨·½¡£

For example, in the example below we use XPointer to point to the fifth item in a list with a unique id of "rock":
ÀýÈ磬ÔÚÏÂÊö°¸ÀýÖУ¬ÎÒÃÇʹÓà XPointer Ö¸ÏòidΪ“lock”ÁбíÖеĵÚÎåÌõ¿î£¬¾ßÌåÈçÏ£º

href="http://www.example.com/cdlist.xml#id('rock').child(5,item)"

ÆÀÂÛ (0) All