本文介绍了C#反序列化包含多个根类型元素的Xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C# - 我如何反序列化具有多种根元素的xml文件?

SampleFile.Xml以下示例包含在一个文件中:



C# - How may I deserialize an xml file the has more than one type of root elements?
SampleFile.Xml Example below all contained in one file:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
   </book>
   <book id="bk102">
      <author>Jeanette, Dasha</author>
      <title>Quack the Duck</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
   </book>
</catalog>







<ServerConfig loggingEnabled="1">
  <Servers>
    <Server host="test1.example.com" port="9999" />
    <Server host="test2.example.com" port="8888" />
  </Servers>
</ServerConfig>

<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <NameList>Linguini</NameList>
  <Item>MACBook</Item>
  <Brand>Apple</Brand>
</Customer>





我''我做很多序列化/反序列化但没有多个类型的根元素。我会感谢你的一些帮助。谢谢!



I''ve done a lot of serialize / deserializing but not with more than one type root element. I''d appreciate some help on this. Thanks ahead!

推荐答案



这篇关于C#反序列化包含多个根类型元素的Xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:43