Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
<?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>


XML
<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!
Posted
Comments
Sergey Alexandrovich Kryukov 11-Apr-13 19:07pm    
Which part of this message could be unclear?
—SA

If you merge the two XML code blocks in one file, or even if your second code block is one single file, it make a file which is not well-formed XML. A real XML has only one root. In this sense, your file ix not XML.

—SA
 
Share this answer
 
Thank you, Sergey. Your answer is precisely what I thought.
I think I will have to extract each individual root element group, and process deserialize it.
Again, thanks!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900