XML SAX parser for scripting using reflection

家住魔仙堡 提交于 2019-12-07 11:19:45

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3720132/xml-sax-parser-for-scripting-using-reflection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!