Inline Versus Out-of-Line Links

Inline Versus Out-of-Line Links

When a link does not contain any of the resources it's linking to, it's called an out-of-line link. Inline links are part of the resources they provide links for, but out-of-link links are not part of the same resource. There's a big movement to try to separate markup from content as much as possible (this is the motivation behind the big switch in HTML 4.0 to working with stylesheets instead of dedicated elements, such as <CENTER> , and the external code modules called behaviors in Internet Explorer). Using out-of-links is very attractive if that's the way you want to go.

You can place out-of-link links in their own documents, called linkbases . The actual set of out-of-line links in a linkbase is called a linkset.

Here's an example. In this case, all the links in this document are to resources that are not part of the document, so this is a linkbase:

 <?xml version = "1.0"?>  <ASTRO_DATA xmlns:xlink="http://www.w3.org/1999/xlink"           xlink:type="extended" xlink:title="Planetary Data">     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml">         xlink:title="START"         xlink:role="START">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 1]">         xlink:title="Mercury"         xlink:role="Mercury">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 2]">         xlink:title="Venus"         xlink:role="Venus">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 3]">         xlink:title="Earth"         xlink:role="Earth">     </PLANET_DATA>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Mercury" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Venus" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Earth" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP> </ASTRO_DATA> 

In this case, all the resources linked to are outside the document. I've added locator links to all the planets in ch15_06.xml, and I've added arcs from the starting position in that document to the planets as well. You typically have three types of links in a linkbase: extended links, locator links, and arcs. You cannot have any links that are of type resource.

Linkbases are subject to the same rules as other XML documents. You can provide them with DTDs if you want to validate them, like I've done here:

Listing ch15_11.xml
 <?xml version = "1.0"?>  <!DOCTYPE ASTRO_DATA  [   <!ELEMENT ASTRO_DATA (PLANET_DATA*, LOOKUP*) >   <!ATTLIST ASTRO_DATA   xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"   xlink:type (extended) #FIXED "extended"   xlink:title CDATA #IMPLIED   xlink:role CDATA #IMPLIED>   <!ELEMENT PLANET_DATA (#PCDATA)>   <!ATTLIST PLANET_DATA   xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"   xlink:type CDATA #FIXED "locator"   xlink:href CDATA #REQUIRED   xlink:role CDATA #IMPLIED   xlink:title CDATA #IMPLIED   xlink:show CDATA #IMPLIED>   <!ELEMENT LOOKUP (#PCDATA)>   <!ATTLIST LOOKUP   xlink:type CDATA #FIXED "arc"   xlink:from CDATA #IMPLIED   xlink:to CDATA #IMPLIED   xlink:show CDATA #IMPLIED   xlink:actuate (onRequest  onLoad  other  none) #IMPLIED>   ]>  <ASTRO_DATA xmlns:xlink="http://www.w3.org/1999/xlink"           xlink:type="extended" xlink:title="Planetary Data">     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml">         xlink:title="START"         xlink:role="START">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 1]">         xlink:title="Mercury"         xlink:role="Mercury">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 2]">         xlink:title="Venus"         xlink:role="Venus">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 3]">         xlink:title="Earth"         xlink:role="Earth">     </PLANET_DATA>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Mercury" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Venus" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Earth" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP> </ASTRO_DATA> 

You can elaborate out-of-line linksets as much as you like. Here, I'm adding arcs that will add a " next " and "previous" link to each planet:

Listing ch15_12.xml
 <?xml version = "1.0"?> <ASTRO_DATA xmlns:xlink="http://www.w3.org/1999/xlink"           xlink:type="extended" xlink:title="Planetary Data">     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml">         xlink:title="START"         xlink:role="START">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 1]">         xlink:title="Mercury"         xlink:role="Mercury">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer(/descendant:: graphics/ccc.gif PLANET[position() = 2]">         xlink:title="Venus"         xlink:role="Venus">     </PLANET_DATA>     <PLANET_DATA xmlns:xlink = "http://www.w3.org/1999/xlink"         xlink:type = "locator"         xlink:show = "embed"         xlink:href="http://www.starpowdermovies.com/ch15_06.xml#xpointer (/descendant:: graphics/ccc.gif PLANET[position() = 3]">         xlink:title="Earth"         xlink:role="Earth">     </PLANET_DATA>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Mercury" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Venus" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>     <LOOKUP xlink:type = "arc" xlink:from = "START"         xlink:to = "Earth" xlink:show="new"         xlink:actuate="onRequest">     </LOOKUP>  <NEXT xlink:type = "arc" xlink:from = "Mercury"   xlink:to = "Venus" xlink:show="new"   xlink:actuate="onRequest">   </NEXT>   <NEXT xlink:type = "arc" xlink:from = "Venus"   xlink:to = "Earth" xlink:show="new"   xlink:actuate="onRequest">   </NEXT>   <NEXT xlink:type = "arc" xlink:from = "Earth"   xlink:to = "Mercury" xlink:show="new"   xlink:actuate="onRequest">   </NEXT>   <PREVIOUS xlink:type = "arc" xlink:from = "Earth"   xlink:to = "Venus" xlink:show="new"   xlink:actuate="onRequest">   </PREVIOUS>   <PREVIOUS xlink:type = "arc" xlink:from = "Venus"   xlink:to = "Mercury" xlink:show="new"   xlink:actuate="onRequest">   </PREVIOUS>   <PREVIOUS xlink:type = "arc" xlink:from = "Mercury"   xlink:to = "Earth" xlink:show="new"   xlink:actuate="onRequest">   </PREVIOUS>  </ASTRO_DATA> 

The next question is: Because out-of-link links are outside all resources that they reference, how does application software that deals with those resources know how to find those links? According to the W3C, you can do that with a special arc whose arc role is www.w3.org/1999/xlink/properties/linkbase. Here's what that looks like:

 <load xlink:type="arc" xlink:from="start.xml"      xlink:to="linkbase.xml" actuate="onLoad"     xlink:arcrole=     "http://www.w3.org/1999/xlink/properties/linkbase"/> 

So far in this chapter, I've said that you use the xlink:href attribute to locate resources, and I've left it at that. However, there is more to it than that: You can do more than just place a URI in this attribute; you can also use XPointers to locate specific locations or sections of a document.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net