Re: XML processing beginner's question
On 8/21/23 18:36, Michael Löscher wrote:
Thank you so far. But what I would like to understand first ist how the different setups work togehter. How are they processed? What is the order of processing, which are the stets taken by the enginge when processing an xml document? Without understanding how that works, it is not possible to apply certain tests on the xml nodes.
As the manual mk.pdf, chapter XVII states: it's a mixture of streaming parser and tree manipulation. The whole xml document is transformed into a Lua table and then processed. But I definitely get the "do my homework for me" vibe, so this will be all from me. Thomas
On 8/21/2023 6:56 PM, Thomas A. Schmitz wrote:
On 8/21/23 18:36, Michael Löscher wrote:
Thank you so far. But what I would like to understand first ist how the different setups work togehter. How are they processed? What is the order of processing, which are the stets taken by the enginge when processing an xml document? Without understanding how that works, it is not possible to apply certain tests on the xml nodes.
As the manual mk.pdf, chapter XVII states: it's a mixture of streaming parser and tree manipulation. The whole xml document is transformed into a Lua table and then processed. But I definitely get the "do my homework for me" vibe, so this will be all from me. in addition:
you need a bit of imagination because basically (depends a bit on what you do) one big nested expansion is going on, as Thomas explained: using setups which are basically macros. The #1 is the current node (but you can store it in a macro and use it later if needed). So, only references are passed around. for thomas: we now also have (in lmtx) \ifxml {id}{pattern} \else \fi \ifxmltext {id}{pattern} \else \fi \ifxmlatt {id}{name}{value} \else \fi \ifxmlattempty {id}{pattern} \else \fi \ifxmlempty {id}{pattern} \else \fi \ifxmlselfempty{id} \else \fi which in some cases is more efficient there is also \xmllastatt etc which can be used after a test which avoids a second lookup Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
-----Ursprüngliche Nachricht----- Von: Hans Hagen via ntg-context
Gesendet: Montag, 21. August 2023 19:09 you need a bit of imagination because basically (depends a bit on what you do) one big nested expansion is going on, as Thomas explained: using setups which are basically macros. The #1 is the current node (but you can store it in a macro and use it later if needed). So, only references are passed around.
for thomas: we now also have (in lmtx)
\ifxml {id}{pattern} \else \fi \ifxmltext {id}{pattern} \else \fi \ifxmlatt {id}{name}{value} \else \fi \ifxmlattempty {id}{pattern} \else \fi \ifxmlempty {id}{pattern} \else \fi \ifxmlselfempty{id} \else \fi
So, these new commands diverge from the older patterns: \xmldoifelse{#1}{pattern}{TRUE}{FALSE} ? Am I reading this correctly? Denis
On 8/22/2023 8:53 AM, denis.maier@unibe.ch wrote:
-----Ursprüngliche Nachricht----- Von: Hans Hagen via ntg-context
Gesendet: Montag, 21. August 2023 19:09 you need a bit of imagination because basically (depends a bit on what you do) one big nested expansion is going on, as Thomas explained: using setups which are basically macros. The #1 is the current node (but you can store it in a macro and use it later if needed). So, only references are passed around.
for thomas: we now also have (in lmtx)
\ifxml {id}{pattern} \else \fi \ifxmltext {id}{pattern} \else \fi \ifxmlatt {id}{name}{value} \else \fi \ifxmlattempty {id}{pattern} \else \fi \ifxmlempty {id}{pattern} \else \fi \ifxmlselfempty{id} \else \fi
So, these new commands diverge from the older patterns: \xmldoifelse{#1}{pattern}{TRUE}{FALSE} ?
they can do the same
Am I reading this correctly? These are more 'texie' commands avoiding a middle layer. A main difference is that in the case of a \if construction one can have lookahead issues when a command in a branch has to look forward and pick up an argument but that happens seldom in xml (probably never).
\ifxml{#1}{/foo} a \orelse\ifxml{#1}{/ofo} b \orelse\ifxml{#1}{/oof} c \orelse\ifempty{xmlatt{#1}{n}} d % could also be a check for number first: \orelse\ifnum\xmlattr{#1}{n}>10\relax % of \norelax e \fi etc (see lowlevel manual) can look a bit less messy that using 5 nested \doifelse's but one has to be aware of the number scanner looking ahead so ending up in the branch because setups have no spaces at the end of lines. (kind of) think of it like this: \protected\def\xmldoifelse#1#2% {\ifxml{#1}{pattern}% \expandafter\firstoftwoareguments \else \expandafter\secondoftwoareguments \fi} performance wise there is a bit of a difference but i never hear complaints so i guess that matters less so: just two ways of programming a solution Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
denis.maier@unibe.ch
-
Hans Hagen
-
Thomas A. Schmitz