* mkiv and xml
@ 2007-09-05 12:34 Hans Hagen
0 siblings, 0 replies; only message in thread
From: Hans Hagen @ 2007-09-05 12:34 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi,
I uploaded a new beta which may be of interest to xml lovers.
The current (mkii) XML handler is based on hooking code into active <
characters. This works ok but has limitations.
In MKIV we will have an alternative method which has a few advantages:
= you have access to arbitrary elements using a subset of xpath
= you can attach fully expandable hooks to elements, using 'setups'
= for manu cases xml processing is faster (no need for definitions and
save/flush)
= with lua as programming environemnt rather tricky manipulations are
possible
The downside of this method is
= loading a document eats a bit of memory
Think of this:
First we load a file (pretty fast btw given that the whole tree is built
in memory in such a way that it can also be flushed as-is)
\xmlload{main}{cont-en.xml}{}
We hook a specific setup into one of the elements
\xmlgrab{main}{cd:command}{cd-demo}
This setup is (here #1 represents the current node):
\startxmlsetups cd-demo
\NC \xmlatt{#1}{name} \NC \xmlatt{#1}{file} \NC \NR
\stopxmlsetups
Now we can say:
\starttabulate[|l|l|]
\NC command \NC file \NC \NR
\xmlall{main}{//cd:command}
\stoptabulate
This gives us a two column table
There is a truckload of (to be documented) commands, for instance one
can filter wlements with:
first \xmlfilter{main}{cd:command/first()} \blank[2*big]
last \xmlfilter{main}{cd:command/last()} \blank[2*big]
first \xmlfirst{main}{cd:command} \blank[2*big]
last \xmllast {main}{cd:command} \blank[2*big]
You can flush whole (sub)trees, access elements by index, etc
A variant of the table builder (without the need for adding hooks) is
\startxmlsetups cd-demo
\NC \xmlatt{#1}{name} \NC \xmlatt{#1}{file} \NC \NR
\stopxmlsetups
\starttabulate[|l|l|]
\NC command \NC file \NC \NR
\xmlcommand{main}{//cd:command}{cd-demo}
\stoptabulate
Or:
\startxmlsetups another-demo
\NC \xmlatt{#1}{name} \NC \xmlatt{#1}{file} \NC \NR
\stopxmlsetups
\starttabulate[|l|l|]
\NC command \NC file \NC \NR
\xmlfilter{main}{//cd:command/command('another-demo')}
\stoptabulate
I reimplemented the presentation mml module (partially) using this
mechanism.
The regular definitions still work but processing a file is done
differently:
\xmlprocess{id}{filename}{optional initiaization setup}
It probably takes a while to get accustomed to this, but this mixture of
stream and tree handling of xml files looks promising.
The current functionality is still experimental and details may change
but the base is there.
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-09-05 12:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-05 12:34 mkiv and xml Hans Hagen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).