ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater <taco@elvenkind.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Which lua XML library is embedded in LMTX?
Date: Fri, 26 Jun 2020 13:42:11 +0200	[thread overview]
Message-ID: <C3C6A533-F34B-472C-A220-8E77D30F40B8@elvenkind.com> (raw)
In-Reply-To: <39CD0D48-A489-44AB-A254-30E7C52E1AD8@rna.nl>

Hi,

> On 25 Jun 2020, at 12:37, Gerben Wierda <Gerben.Wierda@rna.nl> wrote:
> 
> According to the XML manual:
> 
> << 2.1 >> TEX versus LUA
> 
> It will not come as a surprise that we can access xml files from TEX as well as from Lua. In fact there are two methods to deal with xml in Lua. First there are the low level xml functions in the xml namespace. On top of those functions there is a set of functions in the lxml namespace that deals with xml in a more TEXie way.
> 
> << 3.7 >> manipulation
> 
> Having read that, I was loooking for the documentation of the commands that are available in the xml namespace. I want to manipulate a XML tree in LMTX lua. But looking online gives me all kinds of different XML-solutions that are proposed for lua. Which one is embedded in LMTX and available in the xml namespace? But then I get confused because other elements like xml.first, xml.collected are in the xml namespace and mentioned.

None of the prefab solutions are used. The XML parser in ConTeXt is hand-written by Hans.

Most (all?) of the TeX macros like \xmlfirst are in fact thin wrappers around lua code,
see https://source.contextgarden.net/tex/context/base/mkiv/lxml-ini.lua

However, these are currently not documented. Hans wrote the xml-mkiv manual with TeX users
in mind, so there is very little documentation on the Lua side of things. I have plans myself
to write that ‘missing chapter’ but there are a lot of other things on my list of todos as well.

> What I need (in LMTX lua) to add (sub)nodes to the XML node (that I read with xml.first()) because the data I get is broken and I need to fix it before I can use it (and I cannot get good data) The easiest way is to add the correct data to the XML and then use it in my code. If I cannot do that I need to write parallel code that largely does the same as what I already have (ugh)..

Regardless of whether it is doable in principle, this is not the intended use of the 
xml processing in ConTeXT. ConTeXt XML support is for Formatting, not Transformation. 
If you need to actually change the XML structure, I strongly advice to find a solution 
elsewhere.

ConTeXt not only does formatting, but it tries to do this as efficiently and fast
as possible. That means that if you want to modify a parsed tree, you will almost
certainly also have to fix up external indices into that tree and you probably
will have to write the lua mutation functions yourself as well.

So, better look at some binding for libxml2 to some language you like, and then transform
the XML beforehand into something you can confidently use as source for typesetting.

Again: ConTeXt XML support is not meant for XML Transformations.

(my two cents, at least)

Best wishes,
Taco





___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2020-06-26 11:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 10:37 Gerben Wierda
2020-06-26 11:42 ` Taco Hoekwater [this message]

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=C3C6A533-F34B-472C-A220-8E77D30F40B8@elvenkind.com \
    --to=taco@elvenkind.com \
    --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).