Hello Hans,

On Thu, 11 Dec 2014 10:10:16 +0100, Hans Hagen <pra...@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 &gt; 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:l...@pontex.cz
Pontex s. r. o.      | mailto:pon...@pontex.cz | http://www.pontex.cz
Bezová 1658
147 14 Praha 4

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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to