0

我有一个返回数据的 XML 提要。我正在尝试为标签创建一个元素数组,但即使填充了数据,该数组的长度也始终为零。

$.ajax({
                    url: submitUrl,
                    type: "POST",
                    dataType: "xml",
                    data: { request: soapRequest, endPoint: soapEndPoint, header: soapHeader },
                    error: function() {
                        $('#consolelog').html('<p>Failure.</p>');
                    },
                    success: function(soapResponse) {
if (window.DOMParser) {
           parser=new DOMParser();
           xmlDoc=parser.parseFromString(soapResponse,"text/xml");
    }
    else {  //IE
           xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
           xmlDoc.async=false;
           xmlDoc.loadXML(soapResponse); 
    }

    consoleID = document.getElementById('consoleLog');
    consoleID.appendChild(document.createTextNode("xmlDoc = " +  xmlDoc));
    linebreak = document.createElement('br');
    consoleID.appendChild(linebreak);

    var xmlArray = xmlDoc.getElementsByTagName("FAgent");

    consoleID = document.getElementById('consoleLog');
    consoleID.appendChild(document.createTextNode("XMLArray length = " + xmlArray.length));
    linebreak = document.createElement('br');
    consoleID.appendChild(linebreak);

    consoleID = document.getElementById('consoleLog');
    consoleID.appendChild(document.createTextNode("XML Doc = " + xmlDoc.documentElement.childNodes));
    linebreak = document.createElement('br');
    consoleID.appendChild(linebreak);

控制台显示以下输出。

xmlDoc = [object Document]

XMLArray length = 0

XML Doc = [object NodeList]

我想遍历数组,但由于它的长度为 0,我不知道如何访问元素?

当我在浏览器开发人员控制台上检查检查器时,soap 响应也显示为文件

XML 是

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <GenerateQuotesResponse xmlns="http://www.xxxxx.yyyyy/">
         <GenerateQuotesResult>
            <CustomerName>Test</CustomerName>
            <Supplier/>
            <QuoteDate>2012-11-28T08:06:04.3860424-06:00</QuoteDate>
            <QuoteStatus>0</QuoteStatus>
            <QuoteStatusMessage/>
            <As>
               <Apt>
                  <AptStatusCode>0</AptStatusCode>
                  <AptStatusMessage>Apt Processing Successful</AptStatusMessage>
                  <IO>KAL</IO>
                  <IA>AL</IA>
                  <FAgents>
                     <FAgent>
                        <ContractID>2553</ContractID>
                        <AgentName>Test</AgentName>
                        <Address1>Test Ave.</Address1>
                        <Address2/>
                        <PostalCode/>
                        <Phone/>
                        <FAX/>
                        <UnitOfMeasure>US</UnitOfMeasure>
                        <Currency>USD</Currency>
                        <TaxesIncluded>YES</TaxesIncluded>
                        <ColtCardAccepted>YES</ColtCardAccepted>
                        <Note/>
                        <AgentStatusCode>0</AgentStatusCode>
                        <AgentStatusMessage>Agent Processing Successful</AgentStatusMessage>
                        <PricingTiers>
                           <PricingTier>
                              <LowVolume>0.00</LowVolume>
                              <HighVolume>249.00</HighVolume>
                              <UnitPrice>5.15</UnitPrice>
                              <VolUOM>US</VolUOM>
                              <FormattedPrice>5.15</FormattedPrice>
                              <CurrCode>USD</CurrCode>
                           </PricingTier>
                           <PricingTier>
                              <LowVolume>250.00</LowVolume>
                              <HighVolume>499.00</HighVolume>
                              <UnitPrice>5.00</UnitPrice>
                              <VolUOM>US</VolUOM>
                              <FormattedPrice>5.00</FormattedPrice>
                              <CurrCode>USD</CurrCode>
                           </PricingTier>
                            <PricingTier>
                              <LowVolume>2000.00</LowVolume>
                              <HighVolume>999999.00</HighVolume>
                              <UnitPrice>4.55</UnitPrice>
                              <VolUOM>US</VolUOM>
                              <FormattedPrice>4.55</FormattedPrice>
                              <CurrCode>USD</CurrCode>
                           </PricingTier>
                        </PricingTiers>
                     </FAgent>
                     <FAgent>
                        <ContractID>5xxx</ContractID>
                        <AgentName>test 2</AgentName>
                        <Address1/>
                        <Address2/>
                        <PostalCode/>
                        <Phone/>
                        <FAX/>
                        <UnitOfMeasure>US</UnitOfMeasure>
                        <Currency>USD</Currency>
                        <TaxesIncluded>YES</TaxesIncluded>
                        <ColtCardAccepted>YES</ColtCardAccepted>
                        <Note>Test 7</Note>
                        <AgentStatusCode>0</AgentStatusCode>
                        <AgentStatusMessage>Agent Processing Successful</AgentStatusMessage>
                        <PricingTiers>
                           <PricingTier>
                              <LowVolume>0.00</LowVolume>
                              <HighVolume>500.00</HighVolume>
                              <UnitPrice>4.80</UnitPrice>
                              <VolUOM>US</VolUOM>
                              <FormattedPrice>4.80</FormattedPrice>
                              <CurrCode>USD</CurrCode>
                           </PricingTier>
                           <PricingTier>
                              <LowVolume>501.00</LowVolume>
                              <HighVolume>1000.00</HighVolume>
                              <UnitPrice>4.55</UnitPrice>
                              <VolUOM>US</VolUOM>
                              <FormattedPrice>4.55</FormattedPrice>
                              <CurrCode>USD</CurrCode>
                           </PricingTier>
                        </PricingTiers>
                     </FAgent>
                  </FAgents>
               </Apt>
            </As>
         </GenerateQuotesResult>
      </GenerateQuotesResponse>
   </soap:Body>
</soap:Envelope>
4

0 回答 0