【问题标题】:Populate XML tag more than once多次填充 XML 标记
【发布时间】:2013-10-07 11:46:34
【问题描述】:

我的任务是从给定的 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。

我怎样才能实现它?

我尝试只填充一次时间间隔 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};

                };

【问题讨论】:

    标签: c# asp.net .net xml xsd


    【解决方案1】:

    嗯,

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

    【讨论】:

    • 谢谢休。这是有帮助的答案。相反,我尝试使用 foreach 循环。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多