[NTG-context] Ctx & XML

Procházka Lukáš Ing. - Pontex s. r. o. LPr at pontex.cz
Thu Dec 11 12:25:05 CET 2014


Hello Hans,

On Thu, 11 Dec 2014 10:10:16 +0100, Hans Hagen <pragma at wxs.nl> wrote:

>
> 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 at pontex.cz
Pontex s. r. o.      | mailto:pontex at pontex.cz | http://www.pontex.cz
Bezová 1658
147 14 Praha 4

Tel: +420 241 096 751
Fax: +420 244 461 038



More information about the ntg-context mailing list