将xml绑定到数据集时错误无法将SimpleContent列添加到包含元素列或嵌套关系的表中。

时间:2017-03-24 09:55:58

标签: c# asp.net web-services asp.net-web-api

public DataSet ConvertXMLToDataSet(string xmlData)
{
    StringReader stream = null;
    XmlTextReader reader = null;
    try
    {
        DataSet xmlDS = new DataSet();
        stream = new StringReader(xmlData);
        // Load the XmlTextReader from the stream
        reader = new XmlTextReader(stream);
        xmlDS.ReadXml(reader);
        return xmlDS;
    }
    catch
    {
        return null;
    }
    finally
    {
        if (reader != null) reader.Close();
    }
}

如何处理该错误。在reader = new XmlTextReader(stream)上生成错误;请尽快提供解决方案。每当我想在每次生成代码时从给定的xml填充数据集时错误无法将SimpleContent列添加到包含元素列或嵌套关系的表中。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <GetAvailabilityResponse xmlns="http://hermes-it.in/API">
      <GetAvailabilityResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <ResponseStatus>1</ResponseStatus>
        <UserTrackId>RMWVO97099619976967982968064005835242283</UserTrackId>
        <AvailabilityOutput>
          <AvailableFlights>
            <OngoingFlights>
              <AvailFlightSegments>
                <AvailSegments>
                  <AvailSegmentDetails>
                    <FlightId>91</FlightId>
                    <AirlineCode>6E</AirlineCode>
                    <FlightNumber>444</FlightNumber>
                    <AirCraftType/>
                    <Origin>DEL</Origin>
                    <OriginAirportTerminal/>
                    <Destination>LKO</Destination>
                    <DestinationAirportTerminal/>
                    <DepartureDateTime>31/03/2017 06:25:00</DepartureDateTime>
                    <ArrivalDateTime>31/03/2017 07:30:00</ArrivalDateTime>
                    <Duration>1hrs 5mins</Duration>
                    <NumberofStops>0</NumberofStops>
                    <Via/>
                    <CurrencyCode>INR</CurrencyCode>
                    <Currency_Conversion_Rate/>
                    <AvailPaxFareDetails>
                      <PaxFareDetails>
                        <ClassCode>QQZIPB</ClassCode>
                        <ClassCodeDesc>QQZIPB</ClassCodeDesc>
                        <BaggageAllowed>
                          <CheckInBaggage>NoFreeBag</CheckInBaggage>
                          <HandBaggage>7KG*</HandBaggage>
                        </BaggageAllowed>
                        <Adult>
                          <FareBasis>NoFreeBag</FareBasis>
                          <FareType>Refundable</FareType>
                          <BasicAmount>675</BasicAmount>
                          <YQ>275</YQ>
                          <TaxDetails>
                            <AvailTaxItem>
                              <Description>TotalTax</Description>
                              <Amount>572</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>YQ</Description>
                              <Amount>275</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>ServiceTax</Description>
                              <Amount>4</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>OtherCharges</Description>
                              <Amount>0</Amount>
                            </AvailTaxItem>
                          </TaxDetails>
                          <TotalTaxAmount>0</TotalTaxAmount>
                          <GrossAmount>1526</GrossAmount>
                          <Commission>27</Commission>
                        </Adult>
                        <Child i:nil="true"/>
                        <Infant i:nil="true"/>
                        <CancellationCharges/>
                        <ChangePenalty/>
                      </PaxFareDetails>
                      <PaxFareDetails>
                        <ClassCode>QQ0IPR</ClassCode>
                        <ClassCodeDesc>QQ0IPR</ClassCodeDesc>
                        <BaggageAllowed>
                          <CheckInBaggage>15KG</CheckInBaggage>
                          <HandBaggage>7KG*</HandBaggage>
                        </BaggageAllowed>
                        <Adult>
                          <FareBasis>15KG</FareBasis>
                          <FareType>Refundable</FareType>
                          <BasicAmount>875</BasicAmount>
                          <YQ>275</YQ>
                          <TaxDetails>
                            <AvailTaxItem>
                              <Description>TotalTax</Description>
                              <Amount>590</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>YQ</Description>
                              <Amount>275</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>ServiceTax</Description>
                              <Amount>5</Amount>
                            </AvailTaxItem>
                            <AvailTaxItem>
                              <Description>OtherCharges</Description>
                              <Amount>0</Amount>
                            </AvailTaxItem>
                          </TaxDetails>
                          <TotalTaxAmount>0</TotalTaxAmount>
                          <GrossAmount>1745</GrossAmount>
                          <Commission>35</Commission>
                        </Adult>
                        <Child i:nil="true"/>
                        <Infant i:nil="true"/>
                        <CancellationCharges/>
                        <ChangePenalty/>
                      </PaxFareDetails>

                    </AvailPaxFareDetails>
                    <SupplierId>0</SupplierId>
                  </AvailSegmentDetails>
                </AvailSegments>
              </AvailFlightSegments>


            </OngoingFlights>
            <ReturnFlights i:nil="true"/>
          </AvailableFlights>
        </AvailabilityOutput>
      </GetAvailabilityResult>
    </GetAvailabilityResponse>
  </s:Body>
</s:Envelope>

&#13;
&#13;
The following xml gerate error
&#13;
&#13;
&#13;

 **xmlDS.ReadXml(reader);** in this line

如何解决该错误请提供解决方案

0 个答案:

没有答案