0

我的任务是从给定的 XSD 创建 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 类的标签。

我怎样才能实现它?

我尝试仅填充一次时间间隔 qty 的代码如下:

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

                };
4

1 回答 1

0

Erm,

var data = new BrokerConfirmation();
XmlDocument docSave = new XmlDocument();
data.TimeIntervalQuantities = new BrokerConfirmationTimeIntervalQuantity[]
            {
               new BrokerConfirmationTimeIntervalQuantity {...}, 
               // More instances here....
               new BrokerConfirmationTimeIntervalQuantity {...}, 
               new BrokerConfirmationTimeIntervalQuantity {...},
               // etc...
            };
于 2013-10-08T12:39:10.190 回答