2015-09-07 50 views
-1

我有一个可以看起来像这样的XML文件:XML解析 - 磁盘阵列和价值类

<complex> 
    <complex>Value</complex> 
    <complex> 
     <field>Value</field> 
    </complex> 
</complex> 

现在,类领域是这个样子:

[XmlElement] 
public List<Field> field { get; set; } 


public class Field 
{ 

[XmlAttribute] 
public string name; 

[XmlAttribute("ref")] 
public string reference; 

[XmlText] 
public string value; 

} 

我想来解析复合体的价值以及复合体的孩子们的价值。

我认为复杂是一个数组和其他东西?

我将不胜感激!

+0

你的问题不清楚,你应该提供更多的意见。 –

回答

0

使用Visual Studio的“粘贴XML作为班”产生这个(后我做多一点简洁):

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] 
    public partial class complex { 

     [System.Xml.Serialization.XmlElementAttribute("complex")] 
     public complexComplex[] complex1 { get; set; } 

     [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
     public partial class complexComplex { 

      public string field { get; set; } 

      [System.Xml.Serialization.XmlTextAttribute()] 
      public string[] Text { get; set; } 
     } 
    } 

这是你所追求的?