微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Google脚本中通过XML响应调用`getChild'ItemCost currencyID =“ GBP”',NS.getValue`

如何解决如何在Google脚本中通过XML响应调用`getChild'ItemCost currencyID =“ GBP”',NS.getValue`

我从诸如getChild('BuyerEmail',NS).getText()之类的XML响应中获取标准元素没有问题,但是如果结尾处有像getChild('ItemCost currencyID="GBP"',NS).getValue()这样的多余数据,那么我的代码将失败,并显示NUL。 currencyID="GBP" 似乎是问题所在?!?!

我在做什么错了?

代码段:

  var document = XmlService.parse(response);
  var root = document.getRootElement();
  var NS = XmlService.getNamespace("urn:ebay:apis:eBLBaseComponents");
   
  var ack = root.getChildText('Ack',NS);
  var time = root.getChildText('Timestamp',NS);
  var version = root.getChildText('Version',NS);
  var build = root.getChildText('Build',NS);
  var shortmessage = root.getChildText('ShortMessage',NS);
  var longmessage = root.getChildText('LongMessage',NS);
 
  var sr = root.getChildren('SaleRecord',NS);    
  
  for (var i = 0; i < sr.length; i++) {
      
    var orderids = sr[i].getChildren('SellingManagerSoldTransaction',NS);
    
    for (var L = 0; L < orderids.length; L++) {      
     
    var srn = orderids[L].getChild('SaleRecordID',NS).getText();

    var sku = orderids[L].getChild('CustomLabel',NS).getText();
      
    var title = orderids[L].getChild('ItemTitle',NS).getText();

    var qty = orderids[L].getChild('QuantitySold',NS).getText();  
        
    var lineitem = orderids[L].getChild('OrderLineItemID',NS).getText();    
   
    var name = sr[i].getChild('ShippingAddress',NS).getChild('Name',NS).getText();
    var pcode = sr[i].getChild('ShippingAddress',NS).getChild('PostalCode',NS).getText();
    var status = sr[i].getChild('OrderStatus',NS).getChild('CheckoutStatus',NS).getText();
    var paidtime = sr[i].getChild('OrderStatus',NS).getChild('PaidTime',NS).getText();
    var shipped = sr[i].getChild('OrderStatus',NS).getChild('ShippedStatus',NS).getText();
    var email = sr[i].getChild('BuyerEmail',NS).getText();
    var price = sr[i].getChild('SalePrice',NS).getValue();
    var totprice = sr[i].getChild('TotalAmount',NS).getValue();
    
    sheet.appendRow([srn,sku,title,qty,price,totprice,lineitem,name,pcode,status,paidtime,shipped,email]);
      
      }

XML响应示例:

<?xml version="1.0" encoding="utf-8"?>
<GetSellingManagerSoldListingsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <!-- Call-specific Output Fields -->
  <PaginationResult> PaginationResultType
    <TotalNumberOfEntries> int </TotalNumberOfEntries>
    <TotalNumberOfPages> int </TotalNumberOfPages>
  </PaginationResult>
  <SaleRecord> SellingManagerSoldOrderType
    <BuyerEmail> string </BuyerEmail>
    <BuyerID> string </BuyerID>
    <CashOnDeliveryCost currencyID="CurrencyCodeType"> AmountType (double) </CashOnDeliveryCost>
    <CreationTime> dateTime </CreationTime>
    <DaysSinceSale> int </DaysSinceSale>
    <ItemCost currencyID="CurrencyCodeType"> AmountType (double) </ItemCost>
    <OrderStatus> SellingManagerOrderStatusType
      <CheckoutStatus> CheckoutStatusCodeType </CheckoutStatus>
      <FeedbackReceived> CommentTypeCodeType </FeedbackReceived>
      <FeedbackSent> boolean </FeedbackSent>
      <IntegratedMerchantCreditCardEnabled> boolean </IntegratedMerchantCreditCardEnabled>
      <PaidStatus> SellingManagerPaidStatusCodeType </PaidStatus>
      <PaidTime> dateTime </PaidTime>
      <PaymentHoldStatus> PaymentHoldStatusCodeType </PaymentHoldStatus>
      <PaymentMethodUsed> BuyerPaymentMethodCodeType </PaymentMethodUsed>
      <ShippedStatus> SellingManagerShippedStatusCodeType </ShippedStatus>
      <ShippedTime> dateTime </ShippedTime>
      <TotalEmailsSent> int </TotalEmailsSent>
    </OrderStatus>
    <SalePrice currencyID="CurrencyCodeType"> AmountType (double) </SalePrice>
    <SaleRecordID> long </SaleRecordID>
    <SellingManagerSoldTransaction> SellingManagerSoldTransactionType
      <CharityListing> boolean </CharityListing>
      <CustomLabel> string </CustomLabel>
      <ItemID> ItemIDType (string) </ItemID>
      <ItemTitle> string </ItemTitle>
      <ListedOn> TransactionPlatformCodeType </ListedOn>
      <!-- ... more ListedOn values allowed here ... -->
      <ListingType> ListingTypeCodeType </ListingType>
      <OrderLineItemID> string </OrderLineItemID>
      <QuantitySold> int </QuantitySold>
      <Relisted> boolean </Relisted>
      <ReservePrice currencyID="CurrencyCodeType"> AmountType (double) </ReservePrice>
      <SaleRecordID> long </SaleRecordID>
      <SecondChanceOfferSent> boolean </SecondChanceOfferSent>
      <SoldOn> TransactionPlatformCodeType </SoldOn>
      <StartPrice currencyID="CurrencyCodeType"> AmountType (double) </StartPrice>
      <TransactionID> long </TransactionID>
      <Variation> VariationType </Variation>
      <WatchCount> int </WatchCount>
    </SellingManagerSoldTransaction>
    <!-- ... more SellingManagerSoldTransaction nodes allowed here ... -->
    <ShippingAddress> Addresstype
      <Name> string </Name>
      <PostalCode> string </PostalCode>
    </ShippingAddress>
    <ShippingDetails> ShippingDetailsType
      <ShippingType> ShippingTypeCodeType </ShippingType>
    </ShippingDetails>
    <TotalAmount currencyID="CurrencyCodeType"> AmountType (double) </TotalAmount>
    <TotalQuantity> int </TotalQuantity>
    <UnpaidItemStatus> UnpaidItemStatusTypeCodeType </UnpaidItemStatus>
  </SaleRecord>
  <!-- ... more SaleRecord nodes allowed here ... -->
  <!-- Standard Output Fields -->
  <Ack> AckCodeType </Ack>
  <Build> string </Build>
  <CorrelationID> string </CorrelationID>
  <Errors> ErrorType
    <ErrorClassification> ErrorClassificationCodeType </ErrorClassification>
    <ErrorCode> token </ErrorCode>
    <ErrorParameters ParamID="string"> ErrorParameterType
      <Value> string </Value>
    </ErrorParameters>
    <!-- ... more ErrorParameters nodes allowed here ... -->
    <LongMessage> string </LongMessage>
    <SeverityCode> SeverityCodeType </SeverityCode>
    <ShortMessage> string </ShortMessage>
  </Errors>
  <!-- ... more Errors nodes allowed here ... -->
  <HardExpirationWarning> string </HardExpirationWarning>
  <Timestamp> dateTime </Timestamp>
  <Version> string </Version>
</GetSellingManagerSoldListingsResponse>

解决方法

我发现我可以改用:没有currencyID="GBP"的ItemCost,SalePrice和TotalAmount。我错过了这一点,因为ItemCost不能与currencyID="GBP"一起使用。两者

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。