ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Which lua XML library is embedded in LMTX?
@ 2020-06-25 10:37 Gerben Wierda
  2020-06-26 11:42 ` Taco Hoekwater
  0 siblings, 1 reply; 2+ messages in thread
From: Gerben Wierda @ 2020-06-25 10:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1931 bytes --]

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

You can use Lua code to manipulate the tree and it makes no sense to duplicate this in TEX. In the future we might provide an interface to some of this functionality. Keep in mind that manipuating the tree might have side effects as we maintain several indices into the tree that also needs to be updated then. 


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 namespavce and mentioned.

So, maybe I misunderstand things and is the documentation in 

<< 5.5 >> selectors and injectors

This section describes a bit special feature, one that we needed for a project where we could not touch the original content but could add specific sections for our own purpose. Hopefully the example demonstrates its useability. 

But that part I do not understand.

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)..

G

[-- Attachment #1.2: Type: text/html, Size: 5334 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Which lua XML library is embedded in LMTX?
  2020-06-25 10:37 Which lua XML library is embedded in LMTX? Gerben Wierda
@ 2020-06-26 11:42 ` Taco Hoekwater
  0 siblings, 0 replies; 2+ messages in thread
From: Taco Hoekwater @ 2020-06-26 11:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-26 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 10:37 Which lua XML library is embedded in LMTX? Gerben Wierda
2020-06-26 11:42 ` Taco Hoekwater

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).