我有以下的XML提要。我需要做反序列化到对象的列表
。我怎样才能做到这一点在.NET 4.0中C#?
<身体GT;
<游戏>
<运动>
< lot_name>足球< / lot_name>
<奖品>
<! - 对于每一个奖项的division_标签不同的数字结束 - >
< divisions_1>
<师> 1< /部门>
<比赛> 5-2< /匹配>
<支付> $ 10 LT; /收费>
< / divisions_1>
< divisions_2>
<师> 2'; /部门>
<比赛> 3-2< /匹配>
<支付> $ 5℃/收费>
< / divisions_2>
< /奖品>
< /运动>
< /游戏>
< /身体GT;
解决方案
看here,一个很好的解释。
XSD.EXE是自带.NET SDK一个方便的小工具(软件 开发工具包),可以使生活更轻松,当你要赶快去 从XML输入到一个强类型的.NET对象。
如果你开始使用XML文件:
1)在Visual Studio打开XML文件
2)从XML菜单中单击创建模式。这将产生一个XSD 文件。
其余这里
I have the following XML feed. I need to do deserialization to a List
of objects. How can I achieve this in .NET 4.0 C#?
<body>
<games>
<sports>
<lot_name>Football</lot_name>
<prizes>
<!-- For each prize the "division_" tag ends with different number -->
<divisions_1>
<divisions>1</divisions>
<match>5-2</match>
<pay>$10</pay>
</divisions_1>
<divisions_2>
<divisions>2</divisions>
<match>3-2</match>
<pay>$5</pay>
</divisions_2>
</prizes>
</sports>
</games>
</body>
解决方案
Look at here, a good explanation.
xsd.exe is a handy little tool that comes with the .NET SDK (Software Development Kit) that can make life easy when you want to quickly go from an XML input to a strongly-typed .NET object.
If you're starting with an XML file:
1) Open the XML file in Visual Studio
2) From the XML menu click "Create Schema". This will generate a XSD file.
The rest here.