Re: Is XHTML a dead end?

On Fri, 2002-09-27 at 23:04, Eric van der Vlist wrote:

> Yes, it would make things more concrete. I am also quite sure that it 
> would be trivial to write it as a SAX filter especially given the fact 
> that the Hlinks definition seems to precede the use of the mappings
> allowing a brute streaming processing.

Just to illustrate this assertion, here is what it takes to implement
the filter in Python for the basic attributes (xlink:type and
xlink:href) and still assuming that there is only one link per "start
tag":

#!/usr/bin/python

import sys, xml.sax.saxutils, xml.sax, xml.sax.xmlreader

HLINK_NS = 'http://www.w3.org/2002/06/hlink'
XLINK_NS = 'http://www.w3.org/1999/xlink'
ELEMENT = (None, "element")
HREF = (XLINK_NS, "href")
HTYPE = (XLINK_NS, "type")

class Hlink:

	def __init__(self, attrs):
		self.attrs = attrs
	
	def transform(self, attrs):
		res = {}
		locator = self.attrs[(None, "locator")]
		for (ns, n) in attrs.keys():
			if n == self.attrs[(None, "locator")][1:]:
				locator = attrs[(ns, n)]
			else:
				res[(ns, n)] = attrs[(ns, n)]
		res[HTYPE] = "simple"
		res[HREF] = locator
		return attrs.__class__(res, {})


class HlinkFilter(xml.sax.saxutils.XMLFilterBase):

	def __init__ (self):
		xml.sax.saxutils.XMLFilterBase.__init__(self)
		self.Hlinks={}

	def startDocument(self):
		xml.sax.saxutils.XMLFilterBase.startDocument(self)
		xml.sax.saxutils.XMLFilterBase.startPrefixMapping(self, "xlink",
XLINK_NS)

	def startElementNS(self, (uri, name), qname, attrs):
		if uri==HLINK_NS and name=="hlink":
			self.Hlinks[attrs[ELEMENT]] = Hlink(attrs)
		elif self.Hlinks.has_key(name):
			attrs = self.Hlinks[name].transform(attrs)
		xml.sax.saxutils.XMLFilterBase.startElementNS(self, (uri, name),
qname, attrs)

	
oh = xml.sax.saxutils.XMLGenerator()
parser = xml.sax.make_parser()
parser.setFeature("http://xml.org/sax/features/namespaces", 1)
filter = HlinkFilter()
filter.setContentHandler(oh)
parser.setContentHandler(filter)
parser.parse(sys.stdin)


And still, if the source is:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:hlink="http://www.w3.org/2002/06/hlink"
xmlns:vdv="http://eric.van-der-vlist.com/whatever">
<head>
<hlink:hlink namespace="http://www.w3.org/1999/xhtml"
       element="img"
       locator="@src"
       effect="embed"
       actuate="onLoad"
       onFailure="warn"/>
</head>
<body>
<br vdv:foo="bar"/>
<img src="whatever" vdv:foo="bar"/>
</body>
</html>

The result is:

vdv@ibook:~/repros/libxslt$ ./hlink.py < hlink.xml 
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:hlink="http://www.w3.org/2002/06/hlink"
xmlns:vdv="http://eric.van-der-vlist.com/whatever">
<head>
<hlink:hlink locator="@src" onFailure="warn" actuate="onLoad"
element="img" namespace="http://www.w3.org/1999/xhtml"
effect="embed"></hlink:hlink>
</head>
<body>
<br vdv:foo="bar"></br>
<img xlink:type="simple" xlink:href="whatever" vdv:foo="bar"></img>
</body>
</html>vdv@ibook:~/repros/libxslt$ 

This doesn't prove much, but show that if we define a mapping between
HLink and XLink (which will need to take care of multiple links), the
implementation would not add a large overhead on the applications.

Eric

-- 
Rendez-vous à Paris.
                          http://www.technoforum.fr/integ2002/index.html
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------

Received on Saturday, 28 September 2002 04:50:23 UTC