使用 linq 在运行时动态构建 xml 树
这是一个设计问题,吊起大师的胃口。
在以前的版本中,代码使用路径定义,即 /../../ 来提供有关如何构建 artbitary xml 文档的说明。根据 xml 模式,文档必须是正确的,因此路径本质上是 xpath,在 switch 语句中读取和使用以调用代码来构造文档。但不要沉迷于此。
例如,读入和编码时的调用
jim.set("/Alert/Source/DetectTime", "12:03:2010 12:22:21");
将创建
<Alert>
<Source>
<DetectTime>12:03:2010 12:22:21</DetectTime>
</Source>
</Alert>
jim.set 只是将树存储在特定的上下文中。
现在我想使用 linq to xsd 来创建 xml 树,但我仍在寻找一些结构,使用户能够定义如何构建树。 XPath 很简单,但实现起来有点麻烦,不优雅,而且我不方便映射。
任何想法、任何程序、开源、研究,任何东西都会受到赞赏。如果我没有得到答复,我将在 3 天内提供可观的赏金。 鲍勃.
This is a design question, to whet the guru's appetite.
In a previous version, the code was using a path definition, i.e. /../../ to provide instructions on how to build artbitary xml documents. The documents had to be correct according to xml schema, so the path's were essentially xpaths, being read and used in switch statements to call code to construct the doc. But don't get hung up on it.
For example the call when read in and coded
jim.set("/Alert/Source/DetectTime", "12:03:2010 12:22:21");
would create
<Alert>
<Source>
<DetectTime>12:03:2010 12:22:21</DetectTime>
</Source>
</Alert>
The jim.set just stores the tree in a particular context.
Now I'd like to use linq to xsd, to create the xml tree, but i'm still looking for some contruct that will enable a user to define how the tree will be constructed. XPath's are easy, but kinda bulky to implement, not elegant and I don't easy mapping.
Any ideas, any programs, open source, research, anything would be apreciated. If I don't get an answer I'll offer a decent bounty in 3 days.
Bob.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做这样的事情怎么样:
然后您可以运行这样的代码:
它将产生:
我想我可能会发布
CreateXElement
方法的变体,它应该更具可读性。功能是相同的,甚至可能会有边际性能改进。How about doing something like this:
You can then run the code like this:
Which will produce:
I thought I might post a variation of the
CreateXElement
method that should be more readable. The functionality is the same and there may even be a marginal performance improvement.