Sunday, 12 December 2010

Conditionals Again!

There's an Option variant I've not been considering in my tests:

src = """
<choice>
        <option text="Have Sex" next="bonk" />
        <option text="Have A Nap" next="snooze" />
        <option text="Have a threesome" next="kimota">
                <func>
                        return god_mode
                </func>
        </option>
</choice>
"""


I'm having problems getting my head around how to parse this.  I ran the XML through the node number script I posted earlier:

Whitespace
Element: choice
Whitespace
Element: option
Whitespace
Element: option
Whitespace
Element: option
Whitespace
Element: func
Text:
            return god_mode
       
EndElement: func
Whitespace
EndElement: option
Whitespace
EndElement: choice
Whitespace


So, the thing to do seems to be
  • get the option attributes
  • see if there's a descendant func
  • if there is, read the func (another new class!) and look for the end element
  • if not, just return ready for the next option, if there is one
  • use the choice end element to terminate the load
OK, That seems a bit cleared. But I think I'll leave it until tomorrow. I'm getting too tired to think about this stuff.

No comments: