Andrew Florko
Andrew Florko

Reputation: 7750

.Net Xml Serialization: how to collapse misc children nodes to text?

I'd like to use XmlSerializer to deserialize the following structure:

<modules>

  <module name="1">
     <config>
       <miscNodes1/>  ...
     </config>
  </module>

  <module name="2">
     someConfigString1;someConfigString2; 
  </module>


</modules>

to .net classes like that:

[XmlRoot("modules")]
class Config 
{
  [XmlElement("module");
  public List<Module> Modules { get; set; }
}

class Module
{
  [XmlAttribute("name")]
  public string Name { get; set; }

  [???]
  public string Config { get; set; }
}

I'd like to collapse miscellaneous children nodes inside ./modules/module to string: "<config><miscNodes1/></module>" and "someConfigString1;someConfigString2;" (just as if I call InnerXml for element)

XmlText doesn't help me.

How can I do that ?

Thank you in advance!

Upvotes: 1

Views: 138

Answers (1)

Alex
Alex

Reputation: 11

You can use the XmlAnyElement attribute on array of XmlNode, like this: [XmlAnyElement] public XmlNode[] Config { get; set; }

Upvotes: 1

Related Questions