tags:

views:

45

answers:

2

I have reread chapter http://www.rebol.com/docs/core23/rebolcore-15.html on any and parse but can't achieve to parse this kind of hiearchical structure: is it possible ?

<Multipage>
<tab id=1>
  <box id=1>
  </box>
</tab>
<tab id=2>
  <box id=2>
  Hello
  </box>
</tab>
<tab>
</tab>
<tab>
</tab>
</Multipage>
+1  A: 

Gavin MacKenzie's xml-parse script at http://www.rebol.org/view-script.r?script=xml-parse.r1 will parse most XML data. As it is a generalised solution it is understandably more complex than a set of parse rules for a specific XML file.

Peter W A Wood
ok thanks will try.
Rebol Tutorial
+1  A: 

Yes it's possible and not very hard :

data: {...}

ws-chars: charset " ^/^M^-"
ws: [any ws-chars]

rule: [
    ws <Multipage> any [
        ws "<tab" opt [ws "id=" copy id to ">" (print ["tab id:" id])] ">" any [
            ws "<box" opt [ws "id=" copy value to ">" (print ["box id:" id])] ">"
                opt [copy text to "<" (if text [?? text])]
            </box>
        ]
        ws </tab>
    ]
    ws </Multipage> ws
]

parse/all data rule

Running this code, you'll get as output:

tab id: "1"
box id: "1"
text: "^/  "
tab id: "2"
box id: "2"
text: "^/  Hello^/  "
DocKimbel
Seems great will try
Rebol Tutorial