如何将 XML 映射到 C# 对象 [英] How do I map XML to C# objects

查看:39
本文介绍了如何将 XML 映射到 C# 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML,我想将它加载到对象、操作这些对象(设置值、读取值),然后将这些 XML 保存回来.在我创建的结构 (xsd) 中包含 XML 对我来说很重要.

I have an XML that I want to load to objects, manipulate those objects (set values, read values) and then save those XMLs back. It is important for me to have the XML in the structure (xsd) that I created.

一种方法是编写我自己的序列化程序,但是我可以使用它的内置支持或 C# 中的开源吗?

One way to do that is to write my own serializer, but is there a built in support for it or open source in C# that I can use?

推荐答案

您可以使用 xsd.exe 从架构 (xsd) 生成可序列化的 C# 类:

You can generate serializable C# classes from a schema (xsd) using xsd.exe:

xsd.exe dependency1.xsd dependency2.xsd schema.xsd /out:outputDir

如果架构具有依赖项(包含/导入的架构),则它们必须全部包含在同一命令行中.

If the schema has dependencies (included/imported schemas), they must all be included on the same command line.

这篇关于如何将 XML 映射到 C# 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆