Take an xml like this:
<?xml version="1.0"?>
<events>
<event>
<start></start>
<duration></duration>
<begin>{somecallback}</begin>
<complete>{someclass.someproperty = somevalue;}</complete>
</event>
</events>
- I need to be able to parse the xml and execute the string versions of javascript code. I know javascript has an eval function, but I need to know if eval can act on the above
beginandcompleteor if there is an easier way to do this.
Both begin and complete need to either directly access a callback (without parameters), or directly set a value to a property belonging to a class. I’m sure I can eval() a callback, but I am unsure how to proceed with directly setting property values in this manner.
evalwill operate on objects that are in scope as expected:What you should consider is if you need the flexibility of
evalfor what you are doing. Cansomecallbackbe a property of an object? If so, you can callo[fn]()wherefnis “somecallback,” for instance. This is much safer than usingeval. Your<complete>section is too vague for me to recommend a way to avoidevalin the second case however.