|
By Jennifer Kyrnin
Unlike HTML, XML does not have a default method for linking objects. With the XML Linking
Language, or XLink, you can insert elements within XML documents to create and describe
links between resources. But the syntax of links was inspired by HTML and is, in fact,
compatible with HTML links.
Within HTML there are two primary types of links:
- anchors
These are links such as the <a> tag. They create the link, but don't follow
it. That is up to the user of the document.
- objects
These are links such as the <img> tag. They create a link to an external
resource, such as an image, and traverse the link to display or otherwise use the
resource in the new document.
But XLink allows XML to improve upon the HTML links:
- Any XML element can be a link.
In HTML, only a few specific elements can be links.
- XLinks can use XPointers to link to any position in the document.
In HTML, the author must accurately anticipate every possible link position, and
create an anchor (<a name="">) for that position.
- XLink can be used to import text or other markup.
This can only be done with SSI in HTML documents, HTML doesn't allow for
that.
Create an Anchor Link
Using XLink, you can create an anchor link very similar to the standard HTML <a>
tag:
<anchor
xmlns:xlink="http://www.w3.org/1999/xlink/"
xlink:type="simple"
xlink:href="http://webdesign.about.com/library/xml/bl_xml.htm"
xlink:show="new"
xlink:actuate="onRequest"
>XML Resource Library</anchor>
Create an Image Link
You can also create a link to an image and have it display inline in your XML
document:
<image
xmlns:xlink="http://www.w3.org/1999/xlink/"
xlink:type="simple"
xlink:href="http://webdesign.about.com/library/graphics/signature99.gif"
xlink:show="embed"
xlink:actuate="onLoad"
/>
Import Text from Another File
One aspect of XLink that developers will like will be the ability to import text and
other information from external documents:
<importeddata
xmlns:xlink="http://www.w3.org/1999/xlink/"
xlink:type="simple"
xlink:href="http://webdesign.about.com/library/glossary/bldef-xml.htm"
xlink:show="onLoad"
xlink:actuate="embed"
/>
Parts of an XLink
- type
The minimum required attribute of an XLink. If the type is "simple", then the
link will also require the attribute "href".
- href
As with HTML, the href is the location of the link.
- show
Indicates if the links should be new, replace existing content, embed within the
content, some other method, or none and not be shown at all.
- actuate
Actuate tells the parser when to activate the link - onLoad, onRequest, other, and
none.
Previous Features
|