Creating Arcs with the xlink:from and xlink:to AttributesIn simple links, there's little question where to go when the link is activated: The xlink:href attribute tells you all you need to know. However, extended links are more complex. When you want to traverse the link we've created in the last section, what should happen? There are all kinds of paths among the various resources. Each of the possible paths between resources is called an arc. You represent an arc in XML elements by setting the xlink:type attribute to "arc" . To specify how an arc works, you can use attributes such as xlink:show and xlink:actuate . Here's the important part: Arc elements also have xlink:from and xlink:to elements to specify traversal paths. The xlink:from attribute indicates what resource an arc comes from, and the xlink:to attribute indicates what resource it goes to. You set the values of xlink:from and xlink:to to match the xlink:role attribute of the source and target resources. Here's an example. In this case, I'll modify the previous example by renaming the < NAME > element as <START> and including three arcs, one from the <START> element to each of the three <PLANET_DATA> elements (individual arcs always go from one source resource to one target resource). I'll support the arcs with elements named <LOOKUP> . Here's what it looks like: <?xml version = "1.0"?> <ASTRO_DATA xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended" xlink:title="Planetary Data"> <START xlink:type="resource" xlink:role="START"> Planetary Data </START> <DATE xlink:type="resource" xlink:role="LAST_UPDATED"> September 1, 2003 </DATE> <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:: 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:: 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:: 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> As usual, you need to declare the elements and attributes you're using if you want a valid document. That might look something like this with a DTD: Listing ch15_09.xml<?xml version = "1.0"?> <!DOCTYPE ASTRO_DATA [ <!ELEMENT ASTRO_DATA (START, DATE, 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 START (#PCDATA)> <!ATTLIST START xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink" xlink:type CDATA #FIXED "resource" xlink:role CDATA #IMPLIED xlink:title CDATA #IMPLIED> <!ELEMENT DATE (#PCDATA)> <!ATTLIST DATE xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink" xlink:type CDATA #FIXED "resource" xlink:role CDATA #IMPLIED xlink:title 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"> <START xlink:type="resource" xlink:role="START"> Planetary Data </START> <DATE xlink:type="resource" xlink:role="LAST_UPDATED"> September 1, 2003 </DATE> <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:: 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:: 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:: 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 don't need to have an arc refer to one specific resource as I've done here. For example, here all three <PLANET_DATA> elements have the same role, PLANETARY_DATA . So, this single <LOOKUP> element defines three arcs, one to each <PLANET_DATA> resource: Listing ch15_10.xml<?xml version = "1.0"?> <ASTRO_DATA xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended" xlink:title="Planetary Data"> <START xlink:type="resource" xlink:role="START"> Planetary Data </START> <DATE xlink:type="resource" xlink:role="LAST_UPDATED"> September 1, 2003 </DATE> <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:: PLANET[position() = 1]"> xlink:title="Mercury" xlink:role="PLANETARY_DATA"> </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:: PLANET[position() = 2]"> xlink:title="Venus" xlink:role="PLANETARY_DATA"> </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:: PLANET[position() = 3]"> xlink:title="Earth" xlink:role="PLANETARY_DATA"> </PLANET_DATA> <LOOKUP xlink:type = "arc" xlink:from = "START" xlink:to = "PLANETARY_DATA" xlink:show="new" xlink:actuate="onRequest"> </LOOKUP> </ASTRO_DATA> In fact, you can omit an xlink:from or xlink:to attribute altogether. In that case, arcs are created between the particular element and all the locator elements in the extended link (which can include the element that omits the xlink:from or xlink:to attribute itself). The way the xlink:from and xlink:to attributes are actually used is up to the application that's reading the containing document. |