linq 到 xml 或 xsd 方法
似乎有很多关于 linq to xml 以及 xsd 的问题。我想知道作为一名新的 C# 开发人员,我需要利用 xml 为我正在开发的功能提供设置。
看来编写一个 XSD 文档并使用 xsd.exe 生成 C# 代码是一个不错的方法,因为不需要手动编写设置类,节省时间,消除代码等。但是我应该如何比较这种方法使用 Linq to XML?我问似乎我必须编写更多代码来查询 xml,这对我来说不是一个好主意。使用 Linq to XML 到底有什么好处以及可以在哪些情况下应用?
我感觉 Linq to XML 只是另一种使用 XML 的奇特方式。
There appears to be a fair amount of questions about linq to xml, and also about xsd. I want to know as a new C# developer, I need to utilize xml to provide settings for a feature that I am working on.
It seems that writing an XSD document and using xsd.exe to generate the C# code is a good way to go, because there's no need to hand write the settings class, saving time, eliminating code, etc. However how should I compare this method with using Linq to XML? I am asking it seems that I'd have to write more code to query the xml and that's not such a good idea to me. What exactly is the benefit of using Linq to XML and in which situations can it be applied?
I get the feeling that Linq to XML is just another fancy way to work with XML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,Linq-to-XML 只是使用 XML 的另一种方式。它比旧的 System.Xml 命名空间更简单、更简洁。
如果您使用 XML 来存储设置,为什么不使用 System.Configuration 命名空间呢?这是迄今为止在 .NET 应用程序中包含设置的最简单方法。
ConfigurationManager
类允许通过键/值模式从 app.config / web.config 文件简单地检索配置设置。查看 http://msdn.microsoft.com/en-us /library/system.configuration.configurationmanager.aspx
Yes, Linq-to-XML is just another way to work with XML. It is somewhat simpler and more concise than the old
System.Xml
namespace.If you're using XML to store settings, why not use the
System.Configuration
namespace? This is by far the simplest way to include settings in a .NET application. TheConfigurationManager
class allows simply retrieval of configuration settings via a key/value pattern from an app.config / web.config file.Check out http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx