Hello Hans,
On Thu, 11 Dec 2014 10:10:16 +0100, Hans Hagen
that already makes assumptions that it's just data ... the context xml parser is a roundtrip one so a bit more control is provided:
local str = [[ <?xml version="1.0" ?> <a one="1"> <!-- rubish --> <b two="1"/> <b two="2"> c > d </b> </a> ]]
I've added some flags:
inspect(xml.totable(xml.convert(str)))
table={ { "xml version=\"1.0\" ", ["_type"]="instruction", }, "\ ", { "\ ", { " rubish ", ["_type"]="comment", }, "\ ", { ["_tag"]="b", ["_type"]="_element", ["two"]="1", }, "\ ", { "\ c > d\ ", ["_tag"]="b", ["_type"]="_element", ["two"]="2", }, "\ ", ["_tag"]="a", ["_type"]="_element", ["one"]="1", }, ["_type"]="root", }
inspect(xml.totable(xml.convert(str),true))
table={ { "xml version=\"1.0\"", ["_type"]="instruction", }, { { "rubish", ["_type"]="comment", }, { ["_tag"]="b", ["_type"]="_element", ["two"]="1", }, { "c > d", ["_tag"]="b", ["_type"]="_element", ["two"]="2", }, ["_tag"]="a", ["_type"]="_element", ["one"]="1", }, ["_type"]="root", }
inspect(xml.totable(xml.convert(str),true,true))
table={ { [0]="a", { [0]="b", ["two"]="1", }, { [0]="b", "c > d", ["two"]="2", }, ["one"]="1", }, }
The last one is yours. Of course in all cases you loose info that is present in the original representation (where you can also access the nodes via expressions). Don't expect additional helpers for this 'totable' variant.
this is great. I'll try it... Thank you. BTW: In your example, you are using the following enum of "_type": "instruction", "comment", "_element", <-- REALLY UNDERSCORE here? "root", Best regards, Lukas
Hans
-- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz Bezová 1658 147 14 Praha 4 Tel: +420 241 096 751 Fax: +420 244 461 038