Comment analyser une structure hiérarchique dans Rebol?
-
18-09-2019 - |
Question
Je relis le chapitre http://www.rebol.com/docs /core23/rebolcore-15.html sur tout et analyser, mais ne peut pas atteindre pour analyser ce type de structure hiearchical: est-il possible
<Multipage>
<tab id=1>
<box id=1>
</box>
</tab>
<tab id=2>
<box id=2>
Hello
</box>
</tab>
<tab>
</tab>
<tab>
</tab>
</Multipage>
La solution
Oui, il est possible et pas très dur:
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
L'exécution de ce code, vous obtiendrez en sortie:
tab id: "1"
box id: "1"
text: "^/ "
tab id: "2"
box id: "2"
text: "^/ Hello^/ "
Autres conseils
script xml-parse à Gavin MacKenzie http: // www.rebol.org/view-script.r?script=xml-parse.r 1 analysera la plupart des données XML. Comme il est une solution généralisée, il est naturellement plus complexe qu'un ensemble de règles parse un fichier XML spécifique.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow