Container元素中的多个XML元素

时间:2016-10-06 20:01:49

标签: c# xml

我的c#类的输出产生了这个:

<?xml version="1.0" encoding="utf-8"?>
<Clients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FileDate>2016-10-06</FileDate>
  <Client>
    <Record_ID>
      <ClientCode>300063</ClientCode>
      <GCI />
      <Active>0</Active>
    </Record_ID>
    <Address>
      <AddressLine1>1200 John Q. Hammons Drive</AddressLine1>
      <AddressLine2 />
      <AddressLine3 />
      <City>MADISON</City>
      <State>WI</State>
      <Zip>53717</Zip>
      <Country />
      <Phone />
    </Address>
    <Notes>
      <Note>This is a note</Note>
    </Notes>
    <Notes>
      <Note>This is a note</Note>
    </Notes>
  </Client>
</Clients>

我希望它看起来像这样:

<Notes>
      <Note>This is a note</Note>
      <Note>This is a note</Note>
</Notes>

我似乎无法获得像这样序列化的类结构。 有什么想法吗?

我将添加一些相关的类代码

public partial class Client {          
    public ClientNotes Notes {
        get {
            return this.notesField;
        }
        set {
            this.notesField = value;
        }
    }             
    //[XmlElement("Notes")]    
    //public List<ClientNotes> noteList_ { get; set; }    
}

//[XmlElement("Notes")]
public class ClientNotes {    
    private string noteField;    
    [System.Xml.Serialization.XmlElementAttribute(DataType = "string")]
    public string Note {
        get {
            return this.noteField;
        }
        set {
            this.noteField = value;
        }
    }    
    //[XmlElement("Note")]
    public List<Note> noteList_ { get; set; }      
}

1 个答案:

答案 0 :(得分:0)

试试这个

    [XmlRoot("Clients")]
    public partial class Clients
    {
        [XmlElement("Client")]
        public Client noteList_ { get; set; }
    }

    [XmlRoot("Client")]
    public partial class Client
    {
        [XmlElement("Notes")]
        public Notes noteList_ { get; set; }

    }
    [XmlRoot("Notes")]
    public partial class Notes
    {
        [XmlElement("Note")]
        public List<Note> noteList_ { get; set; }
    }

    [XmlRoot("Note")]
    public class Note
    {
        [XmlText]
        public string note_ { get; set; }
    }
相关问题