XLink Example

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

XLINK Basic
XLink HOME
XLink Intro
XLink Syntax
XLink Example
XPointer Example
XLink Summary
References
XLink Reference

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# XLink Example

Let's try to learn some basic XLink syntax by looking at an example.

## The XML Example Document

Look at the following XML document, "bookstore.xml", that represents a few books:

    <?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

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.

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.

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 - Going Further

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.

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.

## Learn XML with <oXygen/> XML Editor - Free Trial!

oXygen helps you learn to define, edit, validate and transform XML documents. Supported technologies include XML Schema, DTD, Relax NG, XSLT, XPath, XQuery, CSS.

Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!

Do you have any XML related questions? Get free answers from the oXygen XML forum and from the video demonstrations.

Download a FREE 30-day trial today!

WEB HOSTING
Ecommerce Components for ASP.NET
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.