我可以使用 Linq-to-xml 来保存我的对象状态,而不必使用/知道 Xpath 和 Xpath 吗? XSD 语法?
我可以使用 Linq-to-xml 来保存我的对象状态,而不必使用/知道 Xpath 和 Xpath 吗? XSD 语法?
IE。真正寻找简单但灵活的方法来持久化对象数据图(例如,有 2 或 3 个具有关联的类) - 如果 Linq-to-xml 就像说“将此图持久化为 XML”一样简单,那么您也可以通过 Linq 查询它,或者再次将其加载到内存中/更改/然后重新保存到 xml 文件。
Can I use Linq-to-xml to persist my object state without having to use/know Xpath & XSD Syntax?
ie. really looking for simple but flexible way to persist a graph of object data (e.g. have say 2 or 3 classes with associations) - if Linq-to-xml were as simple as saying "persist this graph to XML", and then you could also query it via Linq, or load it into memory again/change/then re-save to the xml file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通常不需要 XPath 或 XSD 来使用 LINQ-to-XML,但它也不会执行您想要的操作。
XmlSerializer
很接近,但它是一个树序列化器,而不是图序列化器。DataContractSerializer
(.NET 3.0) 确实通过重载构造函数之一提供图形支持,但不提供对 xml 的完全控制。BinaryFormatter
提供图形支持和基于元数据/类型的工作,但如果您更改程序集,它会非常脆弱,并且不可在平台之间移植。我怀疑要弄清楚的是:我的数据是树还是图?
XmlSerializer
可能已经满足您的需要。You don't usually need XPath or XSD to use LINQ-to-XML, but it also won't do what you want.
XmlSerializer
comes close , but is a tree serializer, not a graph serializer.DataContractSerializer
(.NET 3.0) does offer graph support via one of the overloaded constructors, but doesn't offer full control over the xml.BinaryFormatter
offers graph support and metadata-/type-based workings, but is very brittle if you ever change your assembly, and is not portable between platforms.I suspect the thing to figure out is: is my data a tree or a graph?
XmlSerializer
may already do what you need.