Which lua XML library is embedded in LMTX?
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
Hi,
On 25 Jun 2020, at 12:37, Gerben Wierda
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
participants (2)
-
Gerben Wierda
-
Taco Hoekwater