You can run this example yourself within the asmo module directory. Just
You must have Asmo built with Python support. When you run the test, you
should enter 'foo=bar' and 'bar=baz' as parameters.
Asmo starts with an XML document like this:
Asmo just processes the document sequentially passing XML output to the
current processor. At the beginning the current processor just takes any
output and passes it to stdout. It isn't until we hit a tag with a
namespace qualifier that things change. So until we hit the tag
<test:test> you just get a copy of the document to stdout like this:
At this point we hit a tag with a namespace qualifier. This namespace was
defined in the page tag as 'http://www.sapros.com/xml/schemas/test/1.0'.
When Asmo started, it loaded the python handler which scanned the directory
'taglib' for Python modules. It loaded in each Python module and asked it
which namespace it handled. In this case the module 'test.py' registered
itself as the handler for the 'http://www.sapros.com/xml/schemas/test/1.0'
namespace. So now what happens is all the output gets passed to the
'test.py' module. This continues until we hit another qualified tag. So
this is what gets passed to the 'test.py' module so far:
Now things get really complicated. At this point, 'test.py' has recevied
one tag as input. If you look at that module, you'll notice that when it
gets any tag, it outputs the tag <params:param> in the
'http://www.sapros.com/xml/schemas/params/1.0' namespace. So Asmo
immediately looks up that namespace to see if there is a handler. There is.
The 'params.py' module handles that namespace, so now the 'params.py'
module receives the following text:
If you take a look at the 'params.py' module, you'll notice that it doesn't
output anything until it gets an end tag. So at this point nothing is
output. Now we go on to the next thing processed. In this case it is the
<params:param> tag from the original XML document. Again this is in
the namespace assigned to the 'params.py' module. So we pass this tag an
everything within it to the 'params.py' module. In this case, the
'params.py' module instantiates another object to handle this input. It is
up to the module as to how to handle each tag. It can create completely new
objects or keep using the same one. At this point there are no namespace
changes so we just keep passing text to the 'params.py' module. So at this
point we have passed this text to the second invocation of the 'params.py'
When the 'params.py' module receives a param end tag, it looks up the
parameter named 'foo' in Asmo's parameter dictionary. Asmo keeps a
dictionary of parameters. In the command-line case, these parameters are
typed in as 'key=value' on stdin when you invoke Asmo. If you are using
Asmo as an Apache module, these parameters come from HTML form values. So,
if you typed, foo=bar when you invoked Asmo, then the 'params.py' module
will just output:
Now you have to remember that we are within the <test:test> tags.
That means that the output from the second invocation of the 'params.py'
module goes to thet 'test.py' module. Since there are no namespace changes
until the end test tag, here is what asmo has passed to the 'test.py'
As the test module is getting input, it is outputting it to the first
invocation of the 'params.py' module. So at the end, it has output the
following to the first invocation of the 'params.py' module:
This causes the first invocation of the params module to output the value
of the parameter bar. If you typed 'bar=baz' when Asmo was invoked, then
the 'params.py' module will output:
Now we have finally finished processing up to the tag <test:test>. We
are no longer within any namespace qualified tags, so the rest of the
document is just output straight:
And we are done processing the document. Here is what the run looked like:
(enter name=value pairs on standard input, EOF when done)
what it does |