linq 到 xml 或 xsd 方法

发布于 2024-11-10 03:43:52 字数 296 浏览 0 评论 0原文

似乎有很多关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻安 2024-11-17 03:43:53

是的,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. The ConfigurationManager 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文