[NTG-context] Need help processing XML in luacode
Axel Kielhorn
tex at axelkielhorn.de
Wed Mar 11 09:33:19 CET 2020
Hello Massi,
thanks for you help.
> Am 10.03.2020 um 20:53 schrieb mf <massifr at fastwebnet.it>:
>
> In your tex file, try this:
>
> \startluacode
> settings = {}
> docstruktur = {}
> doclistfile = "doclist.xml"
>
> local striplines = utilities.strings.striplines
>
> cropstring = function(s)
> -- return striplines(s, "prune and collapse")
> return striplines(s)
> end
Well, with this definition I can actually inline that.
> local xmltext = xml.text
>
> doc = xml.load(doclistfile, settings)
>
> for v in xml.collected(doc,"/doclist/psdoc/") do
> -- print (v)
> -- print (xml.text(v,"/docnr"))
> local docnr = cropstring(xml.text(v,"/docnr"))
> print (docnr)
> local docname = cropstring(xmltext(v,"/docname"))
> -- es kann mehrere DOCAN geben!
> local docan = (cropstring(xmltext(v,"/docan")))
> local docverantwortlich = (cropstring(xmltext(v,"/docverantwortlich")))
> docstruktur[docnr]={
> docname = docname,
> docan = docan,
> docverantwortlich = docverantwortlich
> }
Great, that is even shorter.
> end
> \stopluacode
I’m cleaning up my backend code to make it more Lua like.
Greetings
Axel
More information about the ntg-context
mailing list