开发者

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

开发者 https://www.devze.com 2023-03-18 23:56 出处:网络
I\'d like to use XmlSerializer to deserialize the following structure: <modules> <module name=\"1\">

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; }

0

精彩评论

暂无评论...
验证码 换一张
取 消