.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 开发者_如何学JAVAto 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!
You can use the XmlAnyElement attribute on array of XmlNode, like this: [XmlAnyElement] public XmlNode[] Config { get; set; }
精彩评论