使用反射编写脚本的 XML SAX 解析器 [英] XML SAX parser for scripting using reflection

查看:39
本文介绍了使用反射编写脚本的 XML SAX 解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个关于使用 XML 创建假设脚本系统的意见.这个想法是使用 SAX 解析器和 C# 反射.

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.

我找不到允许使用 XML 文件指定自定义操作的库/框架.目前我使用 XML 来序列化应用程序类,错误可能会指定应用程序应使用 XML 执行哪些操作.

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.

所以,我在考虑:

  • C# 的 SAX 解析器实现?
  • XML 脚本约定?

我想实现的是:- 可以分配类实例属性- 可以调用类实例例程

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

假设类实例是隐式的,下面的 XML 脚本对我来说很重要:

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?

推荐答案

Microsoft 没有用于 .Net 的 SAX 解析器.但是,它们确实有一个 XmlTextReader 类,您可以使用它一次读取一个节点的 xml.除了 MSBuild 之外,Microsoft 首先用于 WPF 而现在在 .Net 4.0 WWF 中使用的 xaml 方言似乎与您想要做的脚本类似.我不确定你对这个项目的要求是什么,如果你真的想全力以赴,你可以使用 .Net 中的代码生成技术来编译脚本,以获得更好的性能.

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.

这篇关于使用反射编写脚本的 XML SAX 解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆