由于几天和大量的Google搜索,我试图在这里获得答案。
我想使用Google Apps脚本将Amazon MWS xml解析为Google Sheets。
API调用正在运行,我可以将答案写到工作表的一个单元格中,但是我无法将XML元素拆分为单个单元格。
这是我尝试访问XML元素的方式:
var response = UrlFetchApp.fetch('https://mws.amazonservices.de/Orders/2013-09-01', options);
var responseXml = response.getContentText();
var Sheet_Temp = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Temp')
Sheet_Temp.getRange(1, 1).setValue(response)
var xmlDoc = XmlService.parse(responseXml);
var root = xmlDoc.getRootElement();
var ns = root.getNamespace();
Sheet_Report.getRange(1, 1).setValue(ns);
var row = new Array();
var feed = root.getChild("ListOrdersResult", ns).getChild("Orders", ns).getChild("Order", ns);
var AmazonOrderId = feed.getChildren("AmazonOrderId", ns).getValue();
最后一行引发错误:
TypeError:Objekt中的Funktion getValue [元素:https://mws.amazonservices.com/Orders/2013-09-01] />] nicht gefunden(Zeile 497,日期为“代码”)
这是XML的简短版本。实际文件具有数千种不同的顺序:
<?xml version="1.0"?>
<ListOrdersResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
<ListOrdersResult>
<Orders>
<Order>
<LatestShipDate>2018-01-03T09:07:08Z</LatestShipDate>
<OrderType>StandardOrder</OrderType>
<PurchaseDate>2018-01-01T00:03:57Z</PurchaseDate>
<BuyerEmail>7vndn9example@marketplace.amazon.de</BuyerEmail>
<AmazonOrderId>306-8775721-example</AmazonOrderId>
<IsReplacementOrder>false</IsReplacementOrder>
<LastUpdateDate>2018-01-03T09:37:38Z</LastUpdateDate>
<NumberOfItemsShipped>1</NumberOfItemsShipped>
<ShipServiceLevel>Expedited</ShipServiceLevel>
<OrderStatus>Shipped</OrderStatus>
<SalesChannel>Amazon.de</SalesChannel>
<IsBusinessOrder>false</IsBusinessOrder>
<NumberOfItemsUnshipped>0</NumberOfItemsUnshipped>
<PaymentMethodDetails>
<PaymentMethodDetail>Standard</PaymentMethodDetail>
</PaymentMethodDetails>
<BuyerName>Fabi example</BuyerName>
<OrderTotal>
<CurrencyCode>EUR</CurrencyCode>
<Amount>10.95</Amount>
</OrderTotal>
<IsPremiumOrder>false</IsPremiumOrder>
<EarliestShipDate>2018-01-03T09:07:08Z</EarliestShipDate>
<MarketplaceId>A1PA6795UKMFR9</MarketplaceId>
<FulfillmentChannel>AFN</FulfillmentChannel>
<PaymentMethod>Other</PaymentMethod>
<ShippingAddress>
<City>Winnenden</City>
<PostalCode>71364</PostalCode>
<StateOrRegion>Baden-Württemberg</StateOrRegion>
<CountryCode>DE</CountryCode>
<Name>Fabian example</Name>
<AddressLine2>example 1</AddressLine2>
</ShippingAddress>
<IsPrime>false</IsPrime>
<ShipmentServiceLevelCategory>Expedited</ShipmentServiceLevelCategory>
<SellerOrderId>306-8775721-example</SellerOrderId>
</Order>
<Order>
<LatestShipDate>2018-01-13T17:37:01Z</LatestShipDate>
<OrderType>StandardOrder</OrderType>
<PurchaseDate>2018-01-01T03:17:35Z</PurchaseDate>
<BuyerEmail>004xssfxexample@marketplace.amazon.de</BuyerEmail>
<AmazonOrderId>306-1651353-example</AmazonOrderId>
<IsReplacementOrder>false</IsReplacementOrder>
<LastUpdateDate>2018-01-13T18:07:23Z</LastUpdateDate>
<NumberOfItemsShipped>1</NumberOfItemsShipped>
<ShipServiceLevel>Standard</ShipServiceLevel>
<OrderStatus>Shipped</OrderStatus>
<SalesChannel>Amazon.de</SalesChannel>
<IsBusinessOrder>false</IsBusinessOrder>
<NumberOfItemsUnshipped>0</NumberOfItemsUnshipped>
<PaymentMethodDetails>
<PaymentMethodDetail>Standard</PaymentMethodDetail>
</PaymentMethodDetails>
<BuyerName>F. example</BuyerName>
<OrderTotal>
<CurrencyCode>EUR</CurrencyCode>
<Amount>15.15</Amount>
</OrderTotal>
<IsPremiumOrder>false</IsPremiumOrder>
<EarliestShipDate>2018-01-13T17:37:01Z</EarliestShipDate>
<MarketplaceId>A1PA6795UKMFR9</MarketplaceId>
<FulfillmentChannel>AFN</FulfillmentChannel>
<PaymentMethod>Other</PaymentMethod>
<ShippingAddress>
<City>Golling</City>
<PostalCode>3381</PostalCode>
<StateOrRegion>Niederösterreich</StateOrRegion>
<CountryCode>AT</CountryCode>
<Name>Franz example</Name>
<AddressLine2>example 9</AddressLine2>
</ShippingAddress>
<IsPrime>false</IsPrime>
<ShipmentServiceLevelCategory>Standard</ShipmentServiceLevelCategory>
<SellerOrderId>306-1651353-example</SellerOrderId>
</Order>
</Orders>
<CreatedBefore>2018-01-01T12:00:00Z</CreatedBefore>
</ListOrdersResult>
<ResponseMetadata>
<RequestId>aea97379-21ae-4431-a16d-4a6569c4124b</RequestId>
</ResponseMetadata>
</ListOrdersResponse>
如何在Google工作表中获取此XML?
编辑:我进行了一些更改,但是现在出现以下错误:
TypeError:Objekt中的Funktion getValue [元素:https://mws.amazonservices.com/Orders/2013-09-01] />] nicht gefunden(Zeile 497,日期为“代码”)
答案 0 :(得分:1)
好的,我已经运行了。这是我的解决方案:
$rules->isUnique(['email'])