Changes

Jump to navigation Jump to search
725 bytes added ,  11:57, 24 April 2021
m
xml.preprocessor tracing
In the example above the XML node <tt>id</tt> (<tt>#1</tt>) is passed to Lua by {{cmd|xmlfunction}} command, being transformed from node string <tt>id</tt> (e.g. <tt>xml:name::6</tt>) to Lua table representing the xml elements in the xml tree. To get this table at Lua end <tt>lxml.getid()</tt> function is used (e.g. <tt>xml.text(lxml.getid("#1"), "/price")</tt>). There is no performance gain in doing so.
== XML preprocessor ==
 
Sometimes the XML source is not in the best shape and changing it at the originator side is not possible. You can preprocess it during ConTeXt run to the better shaped XML before it is used.
 
<xmlcode>
<?xml version "1.0"?>
<document>
<p>Altitude 60&amp;nbsp;m</p>
</document>
</xmlcode>
 
will be transformed to the new xml
 
<xmlcode>
<?xml version "1.0"?>
<document>
<p>Altitude 60<nbsp/>m</p>
</document>
</xmlcode>
 
with <tt>lxml.preprocessor</tt> function
 
<xmlcode>
\startluacode
function lxml.preprocessor(data)
data = string.gsub(data, "&amp;nbsp;", "<nbsp/>")
return data
end
\stopluacode
</xmlcode>
 
You can check the result of this transformation with {{cmd|xmlshow}} command.
[[Category:XML]]
[[Category:Programming and Databases]]
138

edits

Navigation menu