DataSet.ReadXML抛出有关重复名称

时间:2015-06-03 16:27:54

标签: c# xml-parsing

我有一个从SOAP Web服务读取结果的进程。我尝试使用ReadXML方法将结果解析为数据集,只要有多个发货日期值,它就会起作用。如果存在单个发货日期值,则会抛出异常,并显示消息“无法添加名为'ShipDate'的列:具有相同名称的嵌套表已属于此DataTable。”

受影响的代码:

    private ShippingDateResponseMain GetResponse(string rawXml) {
        System.IO.StringReader responseBody = new System.IO.StringReader(rawXml);

        ShippingDateResponseMain response = new ShippingDateResponseMain();

        response.ReadXml(responseBody, System.Data.XmlReadMode.InferSchema);

        return response;
    }

好的xml:

<ShipDateResponse>
  <Customer>
    <Company>FDF</Company>
    <Division>FDF</Division>
    <Department>FDF</Department>
    <Number>024418</Number>
    <CutOffTime>00:00</CutOffTime>
  </Customer>
  <ShipDates>
    <ShipDate>2015-06-04</ShipDate>
    <ShipDate>2015-06-05</ShipDate>
  </ShipDates>
</ShipDateResponse>

糟糕的xml:

<ShipDateResponse>
  <Customer>
    <Company>FDF</Company>
    <Division>FDF</Division>
    <Department>FDF</Department>
    <Number>024418</Number>
    <CutOffTime>00:00</CutOffTime>
  </Customer>
  <ShipDates>
    <ShipDate>2015-06-04</ShipDate>
  </ShipDates>
</ShipDateResponse>

0 个答案:

没有答案