我的任务是从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类的TAGS。
我怎样才能实现它?
我试图只填充一次时间间隔数量的代码如下:
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 :(得分:0)
呃,
var data = new BrokerConfirmation();
XmlDocument docSave = new XmlDocument();
data.TimeIntervalQuantities = new BrokerConfirmationTimeIntervalQuantity[]
{
new BrokerConfirmationTimeIntervalQuantity {...},
// More instances here....
new BrokerConfirmationTimeIntervalQuantity {...},
new BrokerConfirmationTimeIntervalQuantity {...},
// etc...
};