XML
  Home arrow XML arrow Page 5 - XPointer Basics
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XPointer Basics
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2001-12-12


    Table of Contents:
  • XPointer Basics
  • The Need For XPointer
  • Revolving Around An Axis
  • Proof Of The Pudding
  • A Fragmented View
  • A Range Of Options
  • Asymmetrically Yours
  • Linking Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    XPointer Basics - A Fragmented View
    ( Page 5 of 8 )

    So that takes care of XPath - but where does XPointer fit in?

    According to the XPointer specification, XPointer serves as the basis for "fragment identifiers" in XLinks. You probably don't know this, but you use fragment identifiers pretty frequently in your daily Web development activities, to link to specific segments of an HTML document - they're the bits following the hash (#) symbol in a standard anchor tag. For example, in the hyperlink


    <a href="http://www.paint.server/colors.html#tangerine">See what tangerine looks like</a>
    the segment

    #tangerine
    would be a fragment identifier.

    Just as fragment identifiers, when attached to an HTML hyperlink, direct the browser to a specific section of an HTML document, XPointers, when attached to an XLink, identify a specific location (or set of locations) within an XML document. This location could be a single character, a text string, a block of contiguous content, or a collection of elements; XPointer allows link authors to specify the location using XPath's built-in functions and conditional tests.

    Let's take a quick example. Consider the following XML document, which I'll call "movie.xml":

    <?xml version="1.0"?> <movie id="67" genre="sci-fi"> <title>X-Men</title> <cast>Hugh Jackman, Patrick Stewart and Ian McKellen</cast> <director>Bryan Singer</director> <year>2000</year> <?play_trailer?> </movie>
    Here's a simple XLink, which uses an XPointer to link to the data for "X-Men" using the movie's "id" attribute:

    <item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="movie.xml#xpointer(id('67'))">X-Men</item>
    As you can see, XPointer, with the able assistance of XPath's location paths, is used to create the fragment identifier that identifies a particular section of the XML data. Without XPointer, link authors would merely be able to reference XML documents; they would have no way of drilling down to specific points within those documents.

    As the example above demonstrates, the syntax for an XPointer is usually

    xpointer(expression)
    For example,

    xpointer(id('67')/title)
    In order to offer link authors the flexibility to use "fallback links" - say, if the document structure or content changes - the XPointer specification allows for more than one XPointer to be specified simultaneously. For example, [code] xpointer(id('67')/cast) xpointer(id('67')/director)
     
     
    The XPointers are evaluated in left-to-right order, and the first successful evaluation is used.

    The XPointer specification also defines two additional "shortcut" forms. The first of these is the so-called "bare name" form, which has been included primarily to maintain compatibility with the existing HTML fragment identifier. An XPointer of this form merely specifies a name, and refers to any element within the document which has an "id" attribute matching that name. Which means that I could write the XPointer above

    xpointer(id('67'))
    as

    67
    and the two would still be equivalent.

    An XPointer may also consist of a "child sequence" - essentially, a series of steps beginning with the document element and drilling down from there to the required resource. Note that the steps are defined in terms of integers, not element names - this XPointer references the first child element of the document element (the movie title.)

    xpointer(/1/1)
    Bare names and child sequences may be combined together if desired.

    As with XPath, you can use predicates and conditional tests to filter out unwanted nodes, and select from a variety of built-in function to further classify the result nodeset. I'm not going to spend any more time on this, though - instead, I'd like to concentrate on XPointer's extensions to XPath, which are primarily in the form of additional constructs to define "points" and "ranges".

     
     
    >>> More XML Articles          >>> More By icarus, (c) Melonfire
     

       

    XML ARTICLES

    - Flex Array Collection Sort and Filtering
    - The Flex Tree Control
    - Flex List Controls
    - Working with Flex and Datagrids
    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT