ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: mkiv and xml
Date: Wed, 05 Sep 2007 14:34:17 +0200	[thread overview]
Message-ID: <46DEA249.2030806@wxs.nl> (raw)

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
___________________________________________________________________________________


                 reply	other threads:[~2007-09-05 12:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46DEA249.2030806@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).