{"id":398,"date":"2007-10-10T12:59:10","date_gmt":"2007-10-10T18:59:10","guid":{"rendered":"http:\/\/blog.codedread.com\/archives\/2007\/10\/10\/more-on-xpointer\/"},"modified":"2007-10-10T12:59:10","modified_gmt":"2007-10-10T18:59:10","slug":"more-on-xpointer","status":"publish","type":"post","link":"https:\/\/www.codedread.com\/blog\/archives\/2007\/10\/10\/more-on-xpointer\/","title":{"rendered":"More On XPointer"},"content":{"rendered":"<p>As an update to <a href=\"http:\/\/blog.codedread.com\/archives\/2007\/10\/09\/397\/\">yesterday's post<\/a> I thought I'd elucidate what I've learned about XPointer.  <!--more--><\/p>\n<p>First, some high-level overview: XPointer is \"an extensible system for XML addressing\", meaning that with it, you can address arbitrary portions of XML documents.  XPointer is specified by the <a href=\"http:\/\/www.w3.org\/TR\/xptr-framework\/\">XPointer Framework<\/a> and then realized through various \"schemes\".<\/p>\n<h3>The element XPointer scheme<\/h3>\n<p>The <a href=\"http:\/\/www.w3.org\/TR\/xptr-element\/\">element<\/a> scheme allows to do relatively simple addressing within an XML document.  You can address an element that has id=\"foobar\" like:  <code>element(foobar)<\/code>.  You can also use a step-wise navigation within the element scheme to get at an arbitrary element.  For example, <code>element(\/1\/3\/5)<\/code> would address the fifth child of the third child of the first element (i.e. the root).  Another example would be <code>element(baz\/2)<\/code> which addresses the second child of the element with id=\"baz\".<\/p>\n<p>Now, how can you <em>use<\/em> an XPointer address?  Well, the way in which I'm interested in doing this is by using it as a URL fragment.  For instance, in yesterday's post I talked about linking to the \"NodeList\" section of <a href=\"http:\/\/www.w3.org\/TR\/DOM-Level-2-Core\/ecma-script-binding.html\">this page<\/a>.   Well to do that with XPointer framework using the Element scheme, my URL would be:<\/p>\n<p><a title=\"Link to the NodeList section in the DOM Level 2 Core Spec\" href=\"http:\/\/www.w3.org\/TR\/DOM-Level-2-Core\/ecma-script-binding.html#element(\/1\/2\/3\/5\/1\/15)\">http:\/\/www.w3.org\/TR\/DOM-Level-2-Core\/ecma-script-binding.html#element(\/1\/2\/3\/5\/1\/15)<\/a><\/p>\n<p>There are some problems with the above, not least of which is that the above document is <strong>NOT<\/strong> well-formed XML (see the &#60;link&#62; tags for starters).  No, unfortunately the document is HTML tag soup.  Could an XPointer implementation support an HTML document?<\/p>\n<div class=\"ads\"><object type=\"text\/html\" width=\"468\" height=\"60\" data=\"http:\/\/www.codedread.com\/gads.php\"><\/object><\/div>\n<p>This brings me to another topic:  Implementation Support of XPointer.  <a href=\"http:\/\/blog.codedread.com\/archives\/2007\/10\/09\/397\/#comment-12149\">Anne<\/a> let me know that Mozilla has some form of XPointer support.  I guess <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=182323\">this bug<\/a> was used to introduce it.  It could enable some really <a title=\"Annotate web pages\" href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=12305\">cool<\/a> <a title=\"Bookmark to a specific element on a page\" href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=159716\">features<\/a>.  But there are some <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=235409\">problems<\/a> with it.  And also, someone wants to <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=388704\">drop support<\/a> because no one uses it yet (you have to love the referenced YouTube video in that bug, though).<\/p>\n<p>So I took the HTML page and reformatted it to be proper XML (defined the &#38;nbsp; entity, closed all &#60;link&#62;, &#60;hr&#62;, &#60;br&#62; elements and wrapped the script in &#60;![CDATA[ ]]&#62; tags).  Once I did this, the following URL worked in Firefox 2.0:<\/p>\n<p>file:\/\/d\/ecma-script-binding.xml#element(\/1\/2\/3\/5\/1\/15)<\/p>\n<p>The fact that this works on XML documents but not on XHTML documents (and especially HTML documents) is a crying shame.  I would love to use this feature to direct people to static, non-changing web pages like specifications...<\/p>\n<h3>The xpointer XPointer scheme<\/h3>\n<p>The element scheme is arguably the least complicated XPointer scheme.  The other scheme of interest is the confusingly named <a href=\"http:\/\/www.w3.org\/TR\/xptr-xpointer\/\">xpointer<\/a> XPointer scheme.  This scheme uses the XPath language to allow richer addressing into documents.  For instance, to address the first instance of text \"foobar\", I could use:  <code>xpointer(string-range(\/, foobar))<\/code>.  Now wouldn't that be cool?  Then I could change my URL to:<\/p>\n<p><a title=\"Link to the first instance of the words 'square bracket' in the DOM Level 2 Core Spec\" href=\"http:\/\/www.w3.org\/TR\/DOM-Level-2-Core\/ecma-script-binding.html#xpointer(string-range(\/,square%20bracket))\">http:\/\/...\/ecma-script-binding.html#xpointer(string-range(\/,square%20bracket))<\/a><\/p>\n<p>so that the reader is instantly drawn to the words \"square bracket\" in that document.<\/p>\n<p>Now I realize that XPointer is inherently brittle and can break on even the simplest document change (hell, regular web links are similarly brittle when you come down to it).  I also realize that the preferred mechanism is for authors to use the id attribute wherever possible, since all browsers support the simple #some-id anchor.  Furthermore, I realize there are problems with trying to use XPointer (a XML technology) on HTML documents.  However, despite all that, I still think this would be a cool feature to be able to use on those web pages that are static and not likely to change over time (\"frozen\" specs, blog entries).  This benefit would be particularly noticed by those people browsing the web on smaller devices with potentially painful-to-access \"text search\" facilities (hint: iPhone and the like).  Of course with any technology, both implementors and authors have to get behind it to make its benefits known.<\/p>\n<div class=\"ads\"><object type=\"text\/html\" width=\"468\" height=\"60\" data=\"http:\/\/www.codedread.com\/gads.php\"><\/object><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As an update to yesterday&#8217;s post I thought I&#8217;d elucidate what I&#8217;ve learned about XPointer.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,25,11,28,30],"tags":[],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-firefox","category-software","category-technology","category-web","category-xml"],"_links":{"self":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":0,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}