XML parser: implementation design
I've always assumed XML documents are a convenient way to store information. Now I've found in XML a good way to "instruct" my application. Delicous.
My problem is integrate the XML parsing in application classes. I'm using C# System.Xml i开发者_如何学运维nterface, I think it's good and portable (right?).
Is there any standard interface which defines methods to organize recursion on xml tags, or methods to implement common xml implementations (maybe in a base class)?
Initially I can think to write an interface which defines
void Read(XmlReader xml);
void Write(XmlREader xml);
What what about nested tags, common tags and so on...
P.S.: I don't think to implement this using LINQ, except in the case it's supported also in Mono (how to determine this)?
Thank you very much! :)
I think you might be looking for Serialization, this is a beginners Tutorial on Serialization
As Binary Worrier mentioned, XML serialization is a simple and efficient option. You can also use Linq to XML, which is supported in Mono since version 2.0 (released in october 2008)
Using xml to "instruct" your app seems backwards to me. I'd be more inclined to use an IronPython script if that was my aim. Xml, normally, is intended to serialize data. Sure you can write a language via xml, but ultimately it is fighting the system. You would also massively struggle to invoke methods (easy enough to set properties etc via XmlSerializer
, though).
Here's A 3 minute guide to embedding IronPython in a C# application to show what might, IMO, be a better way to "instruct" a C# application via a separate script file.
精彩评论