2013-10-07 130 views
0

我的任務是從XSD中創建XML。多次填充XML標籤

我已經使用xsd.exe來生成一個類中有一堆屬性。

其中一個屬性是類的返回類型數組。

例如:

public class BrokerConfirmation 
{ 
    public BrokerConfirmation(); 
    public string Market { get; set; } 
    public string SchemaVersion { get; set; } 
    public string SellerParty { get; set; } 
    public string SenderID { get; set; } 
    public BrokerConfirmationTimeIntervalQuantity[] TimeIntervalQuantities { get; set; } 
} 

BrokerConfirmationTimeIntervalQuantity類是如下

public class BrokerConfirmationTimeIntervalQuantity 
{ 
    public BrokerConfirmationTimeIntervalQuantity(); 

    public decimal ContractCapacity { get; set; } 
    public DateTime DeliveryEndDateAndTime { get; set; } 
    public DateTime DeliveryStartDateAndTime { get; set; } 
    public decimal Price { get; set; } 
    [XmlIgnore] 
    public bool PriceSpecified { get; set; } 
} 

現在我想顯示BrokerConfirmationTimeIntervalQuantity類不止一次的標籤。

我該如何實現它?

我試圖僅一次來填充時間間隔數量的代碼如下:

var data = new BrokerConfirmation(); 
XmlDocument docSave = new XmlDocument(); 
data.TimeIntervalQuantities = new BrokerConfirmationTimeIntervalQuantity[] 
       { 
        new BrokerConfirmationTimeIntervalQuantity { 
         DeliveryStartDateAndTime = Convert.ToDateTime("2013-10-01"), 
         DeliveryEndDateAndTime = Convert.ToDateTime("2013-10-30"), 
         ContractCapacity = trade.Quantity, 
         Price = trade.Price, 
         PriceSpecified = true}; 

       }; 

回答

0

呃,

var data = new BrokerConfirmation(); 
XmlDocument docSave = new XmlDocument(); 
data.TimeIntervalQuantities = new BrokerConfirmationTimeIntervalQuantity[] 
      { 
       new BrokerConfirmationTimeIntervalQuantity {...}, 
       // More instances here.... 
       new BrokerConfirmationTimeIntervalQuantity {...}, 
       new BrokerConfirmationTimeIntervalQuantity {...}, 
       // etc... 
      }; 
+0

由於休。這是有用的答案。相反,我嘗試使用foreach循環。 –