tags:

views:

35

answers:

2

I'd like an opinion about to create an hypothetic scripting system using XML. The idea is to use a SAX parser and C# reflection.

I cannot find a library/framework which allow to specify custom action using XML files. At this time I use XML for serialize application classes, bug could be awesome to specify which actions the application shall execute using XML.

So, I'm thinking about:

  • SAX parser implementation for C#?
  • XML script conventions?

What I'd like to achieve is the: - Possibility to assign a class instance property - Possibility to call class instance routines

Assuming that the class instance is implicit, the following XML script would be gold for me:

<Script>
    <Property Name='SomeProperty'>
        <Value>
            < ... >
        </Value>
    </Property>
    <RoutineCall>
        <Parameters>
            <Parameter Name='ArgName'>
                < ... >
            </Parameter>
        </Parameters>
    </RoutineCall>
</Script>

It is already done by someone? Is it possible?

+1  A: 

Although not SAX parsers, MSBuild and NAnt are excellent examples of XML-based scripting platforms. Both support developing custom actions and have large communities of users who may be able to help as you go along.

If you must build this from scratch, I recommend building serializable classes implementing a simple execution interface (e.g., a Run() method, known events, etc.). You can then use the .NET XmlSerializer to deserialize objects, cast to the interface, and invoke their routines.

kbrimington
+1  A: 

Microsoft does not have a SAX parser for .Net. However, they do have an XmlTextReader class that you can use to read xml a node at a time. In addition to MSBuild it seems as though the xaml dialect used by Microsoft first for WPF and now in .Net 4.0 WWF might be similar to what you want to do as far as scripting. I am not sure what your requirements are for this project, if you really wanted to go all out you could use the code generation technology in .Net to compile the script to possibly get better performance.

Steve Ellinger