w3schools    w3Schools
Search W3Schools :
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

XML Certification
Download XML editor
Custom Programming
Table of contents
XLink Intro
XLink Syntax
XLink Example
XPointer Example
XLink Summary

XLink Reference

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Tutorials
W3Schools Forum

Helping W3Schools


XPointer Example

Previous Next

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

XPointer Example

In this example, we will show you how to use XPointer in conjunction with XLink to point to a specific part of another document.

We will start by looking at the target XML document (the document we are going to link to).

The Target XML Document

The target XML document is called "dogbreeds.xml" and it lists a few different dog breeds:

<?xml version="1.0" encoding="ISO-8859-1"?>
<dog breed="Rottweiler" id="Rottweiler">
  <picture url="http://dog.com/rottweiler.gif" />
  The Rottweiler's ancestors were probably Roman
  drover dogs.....
  Confident, bold, alert and imposing, the Rottweiler
  is a popular choice for its ability to protect....
<dog breed="FCRetriever" id="FCRetriever">
  <picture url="http://dog.com/fcretriever.gif" />
  One of the earliest uses of retrieving dogs was to
  help fishermen retrieve fish from the water....
  The flat-coated retriever is a sweet, exuberant,
  lively dog that loves to play and retrieve....

View the "dogbreeds.xml" file in your browser

Note that the XML document above uses id attributes on each element we may want to link to!

The Linking XML Document

Instead of linking to the entire document (as with XLink), XPointer allows you to link to specific parts of the document. To link to a specific part of a page, add a number sign (#) and an XPointer expression after the URL in the xlink:href attributes.

The expression: #xpointer(id("Rottweiler")) refers to the element in the target document, with the id value of "Rottweiler".

So the xlink:href attribute would look like this: xlink:href="http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))"

However, XPointer allows a shorthand form when linking to an element with an id. You can use the value of the id directly, like this: xlink:href="http://dog.com/dogbreeds.xml#Rottweiler"

The following XML document refers to information of the dog breed for each of my dogs :-), all through XLink and XPointer references:

<?xml version="1.0" encoding="ISO-8859-1"?>
<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">
<mydog xlink:type="simple"
  <description xlink:type="simple"
  Anton is my favorite dog. He has won a lot of.....
<mydog xlink:type="simple"
  <description xlink:type="simple"
  Pluto is the sweetest dog on earth......

Previous Next



Get Your Diploma!

W3Schools' Online Certification Program is the perfect solution for busy professionals who need to balance work, family, and career building.

The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.

The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.

The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.

The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).

Web charting
Web based charting
$15 Domain Name
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
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
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
Home HOME or Top of Page Validate   Validate   W3C-WAI level A conformance icon Printer Friendly  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.