Purple Include

Posted on timeAugust 20th, 2007 by userRay Baxter


Brad Neuberg has worked up a new release of the Purple Include tool that came out of the Hyperscope project. Brad’s description is here.

Basically Purple Include is a mechanism for including the content of other web pages (local or remote) in the body of your page. Here are a couple of examples. Here is a paragraph from a post of mine about Jane Jacob’s work:

Here are two bullet points from the forgotten wisdom of Donald Rumsfeld:

There are three elements of Purple Include.

  1. Markup that you add your page. Depending on what you are trying to do, you add a p, blockquote, q, pre, div, or span element with an href attribute.
    The first blockquote above came from this:

    <blockquote href="http://www.warmroom.com/yesterdays/2006/11/12/network-effects-of-the-opposite-kind/#xpath(//p[6])"></blockquote>

    The xpath expression, #xpath(//p[6]), identifies the relevant paragraph on the referenced page that will be included into you page.

  2. A javascript that you add to your page.

    <script src="http://codinginparadise.org/projects/purple-include/purple-include.js"></script>

    As you can see, Brad is hosting this script on his site, for rapid development and improvements.

    On load, this java script pulls the marked up elements from your page and makes a call to a service that Brad is running to fetch the content to be included on your page. The script inserts this content into the inner html of the element.

    The content is of the class .included and .includeok. I have styled .included in the dark gray that you see instead of the normal silver that I am using for blockquotes, so you can see the change in color as the content is inserted.

  3. Brad is running the service that the javascript calls. This service is doing the xpath queries on the content of the referenced page to get the returned content.

This is an interesting design. When I read about it, the first thing that I thought about was caching of the content. In my examples, I referenced my own pages, as Brad referenced his in his examples. I am sure that if you can read these pages, then Brad’s service can read the referenced pages. I’m probably not going to change the pages that I referenced, but I could.

This could be either a good thing, or a bad thing depending on your purposes. The bad is that the exact elements on a page are subject to change. The sixth paragraph of my Jacob’s post could become the seventh or the fifth if I changed blog templates, or fixed a typo in the post. When including content from another site, all bets are off. Also, the remote server could be off line or inaccessible. Brad could add a cache to his service so that any given xpath element of a referenced url from a specific referrer would return the cached result. There would need to be some way to clear the cache, but see below.

On the other hand, this could be just what you want. This is a way to add dynamic content directly to your page, and you don’t need to worry about updating. For many purposes, having a remote server off line isn’t that big a deal and you are likely to be dealing with more fixed markup than I see on my blog pages. A properly scoped xpath query could pull out exactly what you want from most sites.

A couple of other little things that I came across while playing with this.

You can’t include the same exact url (including xpath parameters) twice. The script uses a hash to map from urls to elements. The server returns the content, the url, and an error and looks up the element in the hash by url. Here is the first of Rumsfeld’s pithy sayings from above:

And here it is again:

Only the second appears; the first is just the roller gif. (You can also see that the styling is different.) This is a bug, or at least an unanticipated use case. You can work around by referring to a non-existent query parameter, so urls

href="http://www.warmroom.com/yesterdays/2006/11/08/rumsfelds-rules/?1#xpath(//div[@class='entry']//li[1])"

and

href="http://www.warmroom.com/yesterdays/2006/11/08/rumsfelds-rules/?2#xpath(//div[@class='entry']//li[2])"

Produce

and

respectively.

Finally, the href attribute isn’t valid with any of p, blockquote, q, pre, div, or span in either html 4 or xhtml. This page is invalid.

tag



Leave a Reply


Search:

Recent Posts

Categories

Relevant Links

AtomPub

Date and Time

GCalendar

GData

iCalendar Tools

Online Calendars

REST

RFCs

Timelines

Zend GData

Feeds: