AmazonOrder xml web语义化
XML Processing Modules — Python 3.7.1 documentation https://docs.python.org/3.7/library/xml.html#xml-vulnerabilities
function TMPdbInsertListOrders($one, $link, $InputAmazonOrderId) { $AmazonOrderId = $InputAmazonOrderId; $ASIN = $one->ASIN; $SellerSKU = $one->SellerSKU; $OrderItemId = $one->OrderItemId; $Title = $one->Title; $QuantityOrdered = $one->QuantityOrdered; $QuantityShipped = $one->QuantityShipped; //TODO CLASS xml DOM mysql--->NOSQL //obj arr str @ $ItemPriceCurrencyCode = $one->ItemPrice->CurrencyCode->__toString(); @ $ItemPriceAmount = $one->ItemPrice->Amount->__toString(); @ $ItemTaxCurrencyCode = $one->ItemTax->CurrencyCode->__toString(); @ $ItemTaxAmount = $one->ItemTax->Amount->__toString(); @ $PromotionDiscountCurrencyCode = $one->PromotionDiscount->CurrencyCode->__toString(); @$PromotionDiscountAmount = $one->PromotionDiscount->Amount->__toString(); $sql = 'INSERT INTO ListOrderItems ('; $sql .= 'AmazonOrderId,ASIN,SellerSKU,OrderItemId,Title,QuantityOrdered,QuantityShipped,ItemPriceCurrencyCode,ItemPriceAmount,ItemTaxCurrencyCode,ItemTaxAmount,PromotionDiscountCurrencyCode,PromotionDiscountAmount'; $sql .= ') VALUES ('; $sql .= '"' . $AmazonOrderId . '","' . $ASIN . '","' . $SellerSKU . '","' . $OrderItemId . '","' . $Title . '","' . $QuantityOrdered . '","' . $QuantityShipped . '","' . $ItemPriceCurrencyCode . '","' . $ItemPriceAmount . '","' . $ItemTaxCurrencyCode . '","' . $ItemTaxAmount . '","' . $PromotionDiscountCurrencyCode . '","' . $PromotionDiscountAmount . '"'; $sql .= ')'; mysqli_query($link, $sql); }
api 在考虑怎么class DOM XML 时,应该跳出这个思维,换NOSQL 数据库。
function TMPdbInsertListOrders($one, $link, $InputAmazonOrderId) { $AmazonOrderId = $InputAmazonOrderId; $ASIN = $one->ASIN; $SellerSKU = $one->SellerSKU; $OrderItemId = $one->OrderItemId; $Title = $one->Title; $QuantityOrdered = $one->QuantityOrdered; $QuantityShipped = $one->QuantityShipped; $ItemPriceCurrencyCode = $one->ItemPrice->CurrencyCode->__toString(); $ItemPriceAmount = $one->ItemPrice->Amount->__toString(); $ItemTaxCurrencyCode = $one->ItemTax->CurrencyCode->__toString(); $ItemTaxAmount = $one->ItemTax->Amount->__toString(); $PromotionDiscountCurrencyCode = $one->PromotionDiscount->CurrencyCode->__toString(); $PromotionDiscountAmount = $one->PromotionDiscount->Amount->__toString(); $sql = 'INSERT INTO ListOrderItems ('; $sql .= 'AmazonOrderId,ASIN,SellerSKU,OrderItemId,Title,QuantityOrdered,QuantityShipped,ItemPriceCurrencyCode,ItemPriceAmount,ItemTaxCurrencyCode,ItemTaxAmount,PromotionDiscountCurrencyCode,PromotionDiscountAmount'; $sql .= ') VALUES ('; $sql .= '"' . $AmazonOrderId . '","' . $ASIN . '","' . $SellerSKU . '","' . $OrderItemId . '","' . $Title . '","' . $QuantityOrdered . '","' . $QuantityShipped . '","' . $ItemPriceCurrencyCode . '","' . $ItemPriceAmount . '","' . $ItemTaxCurrencyCode . '","' . $ItemTaxAmount . '","' . $PromotionDiscountCurrencyCode . '","' . $PromotionDiscountAmount . '"'; $sql .= ')'; mysqli_query($link, $sql); }
<?php echo "\r\n" . date('Y-m-d H:i:s') . " TODO StartScript \r\n"; set_time_limit(0); /* * win-cli-require_once * * */ //return; NULL //return ''; //2017年4月25日 19:59:27 $win_cli_dir = 'D:\cmd\amzapi\amzapitest_com\MarketplaceWebServiceOrders\\'; require_once($win_cli_dir . 'Samples\.config.inc.php'); require_once($win_cli_dir . 'Samples\.config.db.php'); //wStartThisScript(); require_once($win_cli_dir . 'Client.php'); require_once($win_cli_dir . 'Model\ListOrderItemsRequest.php'); require_once($win_cli_dir . 'Model\ListOrderItemsResponse.php'); require_once($win_cli_dir . 'Model\ListOrderItemsByNextTokenRequest.php'); require_once($win_cli_dir . 'Model\ListOrderItemsByNextTokenResponse.php'); $serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01"; $config = array( 'ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3, ); $service = new MarketplaceWebServiceOrders_Client( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config); //TODO StartScript //bug limit page $sql = 'SELECT DISTINCT AmazonOrderId FROM listorders'; foreach ($dbh->query($sql) as $row) { echo "\r\n" . date('Y-m-d H:i:s') . "\r\n"; $InputAmazonOrderId = $row['AmazonOrderId']; $sql_inserted = 'SELECT id FROM ListOrderItems WHERE AmazonOrderId="' . $InputAmazonOrderId . '" LIMIT 1'; if ($insertedRes = $dbh->query($sql_inserted)->fetchColumn() > 0) { echo "\r\n" . $InputAmazonOrderId . " inserted\r\n"; continue; } ////TODO modify ExponentialBackoffSleep(); $request = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest(); $request->setSellerId(MERCHANT_ID); $request->setAmazonOrderId($InputAmazonOrderId); $request->setMWSAuthToken(MWSAUTH_TOKEN); invokeListOrderItems($service, $request); } function ExponentialBackoffSleep($intervalSeconds = 8) { $unixTimestamp = time(); $ExponentialBackoff = rand(1, $intervalSeconds); if ($unixTimestamp % $intervalSeconds == 0) sleep($ExponentialBackoff); } //TODO // Exception to DB //to move function apiCaughtException($ex) { echo("Caught Exception: " . $ex->getMessage() . "\n"); echo("Response Status Code: " . $ex->getStatusCode() . "\n"); echo("Error Code: " . $ex->getErrorCode() . "\n"); echo("Error Type: " . $ex->getErrorType() . "\n"); echo("Request ID: " . $ex->getRequestId() . "\n"); echo("XML: " . $ex->getXML() . "\n"); echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n"); } function invokeListOrderItems(MarketplaceWebServiceOrders_Interface $service, $request) { global $link; global $InputAmazonOrderId; try { $response = $service->ListOrderItems($request); //TODO class XML(){} $dom = new DOMDocument(); $dom->loadXML($response->toXML()); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $savexml = $dom->saveXML(); $readxml = simplexml_load_string($savexml); $obj = $readxml->ListOrderItemsResult->OrderItems; foreach ($obj->children() AS $one) { TMPdbInsertListOrders($one, $link, $InputAmazonOrderId); } echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n"); } catch (MarketplaceWebServiceOrders_Exception $ex) { apiCaughtException($ex); } } //TODO EndScript echo "\r\n" . date('Y-m-d H:i:s') . " TODO EndScript \r\n";
$response = $service->ListOrderItems($request); //TODO class XML(){} $dom = new DOMDocument(); $dom->loadXML($response->toXML()); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $savexml = $dom->saveXML(); $readxml = simplexml_load_string($savexml); var_dump($readxml); // die(); $obj = $readxml->ListOrderItemsResult->OrderItems; foreach ($obj->children() AS $one) { $ItemTax = $one->ItemTax; $w = $one->ItemTax->CurrencyCode->__toString(); var_dump($w); die(); //TMPdbInsertListOrders($one, $link, $InputAmazonOrderId); }
2017-04-27 14:31:16 object(SimpleXMLElement)#9 (2) { ["ListOrderItemsResult"]=> object(SimpleXMLElement)#8 (2) { ["AmazonOrderId"]=> string(19) "123-0138431-1234567" ["OrderItems"]=> object(SimpleXMLElement)#22 (1) { ["OrderItem"]=> object(SimpleXMLElement)#12 (10) { ["ASIN"]=> string(10) "12345M83D8" ["SellerSKU"]=> string(17) "ABCDEM025AB-USAA1" ["OrderItemId"]=> string(14) "12345841535298" ["Title"]=> string(125) "ABC Temperature Humidity Monitor, Indoor Room Wireless Digital Humidity Gauge Humidity Monitor Thermometer and Hygrometer" ["QuantityOrdered"]=> string(1) "1" ["QuantityShipped"]=> string(1) "1" ["ItemPrice"]=> object(SimpleXMLElement)#18 (2) { ["CurrencyCode"]=> string(3) "USD" ["Amount"]=> string(5) "123456.99" } ["ItemTax"]=> object(SimpleXMLElement)#17 (2) { ["CurrencyCode"]=> string(3) "USD" ["Amount"]=> string(4) "0.00" } ["PromotionDiscount"]=> object(SimpleXMLElement)#16 (2) { ["CurrencyCode"]=> string(3) "USD" ["Amount"]=> string(4) "0.00" } ["PromotionIds"]=> object(SimpleXMLElement)#21 (0) { } } } } ["ResponseMetadata"]=> object(SimpleXMLElement)#7 (1) { ["RequestId"]=> string(36) "1234c610-1f16-4439-a44d-3e67aad00f83" } }
Returns text content that is directly in this element. Does not return text content that is inside this element's children.
$NextToken = $readxml->ListOrdersResult->NextToken;
SimpleXMLElement Object ( [0] => Jg7v+SJzXjGaJqJYLDm0ZIfVkJJPpovR/DC1hSLylGRUojdU4H46trQzazHyYVyLqBXdLk4iogwM3B3rhUPcuUK6S7uoSULaabcFCEBqvL7LwiR9ykq0GiJ0wMvlylZkWQWPqGlbsnM84qdTrqNK4xcLF35dmoM9lMX1Zf5tksl33LTkQNapIruZIF9n45mtnrZ4AbBdBTeicp5jJPQPcgCy5/GuGI4OLzyB960RsbIZEWUDFvtT5/IsvtC4o4qlDI+q+jAW0lFkh8MWm7HJj7CXSaG7w7Y22ZC4fGUFmXZk2azcFx+lUxov02311Q0e1Yr+D0zvLTlxrBy2GCH8wUSFDXWKBiirNm3hhBE2SmDDrca+rjov3cpDAGiKxo7Bm0u54yUEcqR1PO4RyTeA2S73c5UbfvqtgQNSshBto/wnqiaNsmF5ymDg3EY9z6o1VIu63QjSN78= )
$w = $NextToken->__toString();
$NextToken
= $w;
http://php.net/manual/en/simplexmlelement.tostring.php
<?php /******************************************************************************* * Copyright 2009-2017 Amazon Services. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. ******************************************************************************* * PHP Version 5 * @category Amazon * @package Marketplace Web Service Orders * @version 2013-09-01 * Library Version: 2017-02-22 * Generated: Thu Mar 02 12:41:08 UTC 2017 */ /** * List Orders Sample */ require_once('.config.inc.php'); require_once('.config.db.php'); /************************************************************************ * Instantiate Implementation of MarketplaceWebServiceOrders * * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants * are defined in the .config.inc.php located in the same * directory as this sample ***********************************************************************/ // More endpoints are listed in the MWS Developer Guide //North America: $serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01"; // Europe //$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01"; // Japan //$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01"; // China //$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01"; $config = array( 'ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3, ); $service = new MarketplaceWebServiceOrders_Client( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config); /************************************************************************ * Uncomment to try out Mock Service that simulates MarketplaceWebServiceOrders * responses without calling MarketplaceWebServiceOrders service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under MarketplaceWebServiceOrders/Mock tree * ***********************************************************************/ // $service = new MarketplaceWebServiceOrders_Mock(); /************************************************************************ * Setup request parameters and uncomment invoke to try out * sample for List Orders Action ***********************************************************************/ // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_ListOrders $request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest(); $request->setSellerId(MERCHANT_ID); #D-well $request->setMWSAuthToken(MWSAUTH_TOKEN); $request->setCreatedAfter('2017-04-10'); # &LastUpdatedAfter=2013-08-01T18%3A12%3A21 // // object or array of parameters invokeListOrders($service, $request); /** * Get List Orders Action Sample * Gets competitive pricing and related information for a product identified by * the MarketplaceId and ASIN. * * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface * @param mixed $request MarketplaceWebServiceOrders_Model_ListOrders or array of parameters */ function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request) { global $link; try { $response = $service->ListOrders($request); // echo("Service Response\n"); // echo("=============================================================================\n"); $dom = new DOMDocument(); $dom->loadXML($response->toXML()); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; //echo $dom->saveXML(); $savexml = $dom->saveXML(); $readxml = simplexml_load_string($savexml); //print_r($readxml); $NextToken = $readxml->ListOrdersResult->NextToken; $w = $NextToken->__toString(); //print_r($w); $obj = $readxml->ListOrdersResult->Orders; foreach ($obj->children() AS $one) { $AmazonOrderId = $one->AmazonOrderId; $SellerOrderId = $one->SellerOrderId; $PurchaseDate = $one->PurchaseDate; $LastUpdateDate = $one->LastUpdateDate; $OrderStatus = $one->OrderStatus; $FulfillmentChannel = $one->FulfillmentChannel; $SalesChannel = $one->SalesChannel; $ShipServiceLevel = $one->ShipServiceLevel; $ShippingAddressName = $one->ShippingAddress->Name; $ShippingAddressAddressLine1 = $one->ShippingAddress->AddressLine1; $ShippingAddressCity = $one->ShippingAddress->City; $ShippingAddressStateOrRegion = $one->ShippingAddress->StateOrRegion; $ShippingAddressPostalCode = $one->ShippingAddress->PostalCode; $ShippingAddressCountryCode = $one->ShippingAddress->CountryCode; $OrderTotalCurrencyCode = $one->OrderTotal->CurrencyCode; $OrderTotalAmount = $one->OrderTotal->Amount; $NumberOfItemsShipped = $one->NumberOfItemsShipped; $NumberOfItemsUnshipped = $one->NumberOfItemsUnshipped; $PaymentExecutionDetail = $one->PaymentExecutionDetail; $PaymentMethodDetailsPaymentMethodDetail = $one->PaymentMethodDetails->PaymentMethodDetail; // $PaymentMethodDetailsPaymentMethodDetail = $one->PaymentMethodDetails; $MarketplaceId = $one->MarketplaceId; $BuyerEmail = $one->BuyerEmail; $BuyerName = $one->BuyerName; $ShipmentServiceLevelCategory = $one->ShipmentServiceLevelCategory; $OrderType = $one->OrderType; $EarliestShipDate = $one->EarliestShipDate; $LatestShipDate = $one->LatestShipDate; $IsBusinessOrder = $one->IsBusinessOrder; $IsPrime = $one->IsPrime; $IsPremiumOrder = $one->IsPremiumOrder; $IsReplacementOrder = $one->IsReplacementOrder; $sql = 'INSERT INTO ListOrders ('; $sql .= 'SellerID,AmazonOrderId,SellerOrderId,PurchaseDate,LastUpdateDate,OrderStatus,FulfillmentChannel,SalesChannel,ShipServiceLevel,ShippingAddressName,ShippingAddressAddressLine1,ShippingAddressCity,ShippingAddressStateOrRegion,ShippingAddressPostalCode,ShippingAddressCountryCode,OrderTotalCurrencyCode,OrderTotalAmount,NumberOfItemsShipped,NumberOfItemsUnshipped,PaymentExecutionDetail,PaymentMethodDetailsPaymentMethodDetail,MarketplaceId,BuyerEmail,BuyerName,ShipmentServiceLevelCategory,OrderType,EarliestShipDate,LatestShipDate,IsBusinessOrder,IsPrime,IsPremiumOrder,IsReplacementOrder '; $sql .= ') VALUES ('; $sql .= '"' . MERCHANT_ID . '","' . $AmazonOrderId . '","' . $SellerOrderId . '","' . $PurchaseDate . '","' . $LastUpdateDate . '","' . $OrderStatus . '","' . $FulfillmentChannel . '","' . $SalesChannel . '","' . $ShipServiceLevel . '","' . $ShippingAddressName . '","' . $ShippingAddressAddressLine1 . '","' . $ShippingAddressCity . '","' . $ShippingAddressStateOrRegion . '","' . $ShippingAddressPostalCode . '","' . $ShippingAddressCountryCode . '","' . $OrderTotalCurrencyCode . '","' . $OrderTotalAmount . '","' . $NumberOfItemsShipped . '","' . $NumberOfItemsUnshipped . '","' . $PaymentExecutionDetail . '","' . $PaymentMethodDetailsPaymentMethodDetail . '","' . $MarketplaceId . '","' . $BuyerEmail . '","' . $BuyerName . '","' . $ShipmentServiceLevelCategory . '","' . $OrderType . '","' . $EarliestShipDate . '","' . $LatestShipDate . '","' . $IsBusinessOrder . '","' . $IsPrime . '","' . $IsPremiumOrder . '","' . $IsReplacementOrder . '"'; $sql .= ')'; // var_dump($sql); mysqli_query($link, $sql); } echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n"); } catch (MarketplaceWebServiceOrders_Exception $ex) { echo("Caught Exception: " . $ex->getMessage() . "\n"); echo("Response Status Code: " . $ex->getStatusCode() . "\n"); echo("Error Code: " . $ex->getErrorCode() . "\n"); echo("Error Type: " . $ex->getErrorType() . "\n"); echo("Request ID: " . $ex->getRequestId() . "\n"); echo("XML: " . $ex->getXML() . "\n"); echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n"); } } /* * * 语句模版 $w = array('AmazonOrderId','SellerOrderId','PurchaseDate','LastUpdateDate','OrderStatus','FulfillmentChannel', 'SalesChannel','ShipServiceLevel','ShippingAddressName','ShippingAddressAddressLine1','ShippingAddressCity','ShippingAddressStateOrRegion','ShippingAddressPostalCode','ShippingAddressCountryCode','OrderTotalCurrencyCode','OrderTotalAmount','NumberOfItemsShipped','NumberOfItemsUnshipped','PaymentExecutionDetail','PaymentMethodPaymentMethodDetails','MarketplaceId','BuyerEmail','BuyerName','ShipmentServiceLevelCategory','OrderType','EarliestShipDate','LatestShipDate','IsBusinessOrder','IsPrime','IsPremiumOrder','IsReplacementOrder' ); $sql = ''; $sqlb = ''; foreach($w as $one){ echo '$',$one,'=$one->',$one,';<br>'; $sql.='"'.$one.'"'; $sqlb.='"$'.$one.'",'; } echo '<br>'; echo $sql; echo '<br>'; echo $sqlb; */ /* [PaymentMethodDetails] => SimpleXMLElement Object ( [PaymentMethodDetail] => Array ( [0] => CreditCard [1] => GiftCertificate ) ) [PaymentMethodDetails] => SimpleXMLElement Object ( [PaymentMethodDetail] => Array ( [0] => CreditCard [1] => Other ) ) [PaymentMethodDetails] => SimpleXMLElement Object ( [PaymentMethodDetail] => CreditCard ) * * */
w
<?php /******************************************************************************* * Copyright 2009-2017 Amazon Services. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. ******************************************************************************* * PHP Version 5 * @category Amazon * @package Marketplace Web Service Orders * @version 2013-09-01 * Library Version: 2017-02-22 * Generated: Thu Mar 02 12:41:08 UTC 2017 */ /** * List Orders Sample */ require_once('.config.inc.php'); /************************************************************************ * Instantiate Implementation of MarketplaceWebServiceOrders * * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants * are defined in the .config.inc.php located in the same * directory as this sample ***********************************************************************/ // More endpoints are listed in the MWS Developer Guide //North America: $serviceUrl = "https://mws.amazonservices.com/Orders/2017-03-01"; // Europe //$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01"; // Japan //$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01"; // China //$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01"; $config = array( 'ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3, ); $service = new MarketplaceWebServiceOrders_Client( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config); /************************************************************************ * Uncomment to try out Mock Service that simulates MarketplaceWebServiceOrders * responses without calling MarketplaceWebServiceOrders service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under MarketplaceWebServiceOrders/Mock tree * ***********************************************************************/ // $service = new MarketplaceWebServiceOrders_Mock(); /************************************************************************ * Setup request parameters and uncomment invoke to try out * sample for List Orders Action ***********************************************************************/ // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_ListOrders $request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest(); $request->setSellerId(MERCHANT_ID); #D-well $request->setMWSAuthToken(MWSAUTH_TOKEN); // // object or array of parameters invokeListOrders($service, $request); /** * Get List Orders Action Sample * Gets competitive pricing and related information for a product identified by * the MarketplaceId and ASIN. * * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface * @param mixed $request MarketplaceWebServiceOrders_Model_ListOrders or array of parameters */ function invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request) { try { $response = $service->ListOrders($request); // echo("Service Response\n"); // echo("=============================================================================\n"); $dom = new DOMDocument(); $dom->loadXML($response->toXML()); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; //echo $dom->saveXML(); $savexml = $dom->saveXML(); $readxml = simplexml_load_string($savexml); print_r($readxml); $obj = $readxml->ListOrdersResult->Orders; foreach ($obj->children() AS $one) { var_dump($one); echo '<br><br>'; } echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n"); } catch (MarketplaceWebServiceOrders_Exception $ex) { echo("Caught Exception: " . $ex->getMessage() . "\n"); echo("Response Status Code: " . $ex->getStatusCode() . "\n"); echo("Error Code: " . $ex->getErrorCode() . "\n"); echo("Error Type: " . $ex->getErrorType() . "\n"); echo("Request ID: " . $ex->getRequestId() . "\n"); echo("XML: " . $ex->getXML() . "\n"); echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n"); } }
w
如何理解 Web 语义化? - 知乎 https://www.zhihu.com/question/20455165
“
作者:田乐
链接:https://www.zhihu.com/question/20455165/answer/15206040
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
”
w
web语义化是发展趋势;在web语义化这一面xml较html5更有先天优势,更利于web root去理解、AI化,和但该优势也导致其目前不便于服务端语言生成和前端页面交互处理时的DOM操作;
https://www.w3schools.com/php/php_xml_parsers.asp
What is XML?
The XML language is a way to structure data for sharing across websites.
Several web technologies like RSS Feeds and Podcasts are written in XML.
XML is easy to create. It looks a lot like HTML, except that you make up your own tags.
What is an XML Parser?
Tree-Based Parsers
Tree-based parsers holds the entire document in Memory and transforms the XML document into a Tree structure. It analyzes the whole document, and provides access to the Tree elements (DOM).
This type of parser is a better option for smaller XML documents, but not for large XML document as it causes major performance issues.
Example of tree-based parsers:
- SimpleXML
- DOM
Event-Based Parsers
Event-based parsers do not hold the entire document in Memory, instead, they read in one node at a time and allow you to interact with in real time. Once you move onto the next node, the old one is thrown away.
This type of parser is well suited for large XML documents. It parses faster and consumes less memory.
Example of event-based parsers:
- XMLReader
- XML Expat Parser
- 基于树的解析器:这种解析器把 XML 文档转换为树型结构。它分析整篇文档,并提供了 API 来访问树种的元素,例如文档对象模型 (DOM)。
- 基于事件的解析器:将 XML 文档视为一系列的事件。当某个具体的事件发生时,解析器会调用函数来处理。
SimpleXML is a PHP extension that allows us to easily manipulate and get XML data.
The SimpleXML Parser
SimpleXML is a tree-based parser.
SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout.
SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects.
Compared to DOM or the Expat parser, SimpleXML takes a fewer lines of code to read text data from an element.
Installation
As of PHP 5, the SimpleXML functions are part of the PHP core. No installation is required to use these functions.
PHP SimpleXML - Read From String
The PHP simplexml_load_string() function is used to read XML data from a string.
The example below shows how to use the simplexml_load_string() function to read XML data from a string:
CODE
$myXMLData = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>"; $xml = simplexml_load_string($myXMLData) or die("Error: Cannot create object"); print_r($xml);
SimpleXMLElement Object ( [to] => Tove [from] => Jani [heading] => Reminder [body] => Don't forget me this weekend! )
Error Handling Tip: Use the libxml functionality to retrieve all XML errors when loading the document and then iterate over the errors. The following example tries to load a broken XML string:
CODE
libxml_use_internal_errors(true); $myXMLData = "<?xml version='1.0' encoding='UTF-8'?> <document> <user>John Doe</wronguser> <email>john@example.com</wrongemail> </document>"; $xml = simplexml_load_string($myXMLData); if ($xml === false) { echo "Failed loading XML: "; foreach (libxml_get_errors() as $error) { echo "<br>", $error->message; } } else { print_r($xml); }
Failed loading XML:
Opening and ending tag mismatch: user line 3 and wronguser
Opening and ending tag mismatch: email line 4 and wrongemail
PHP SimpleXML - Read From File
The PHP simplexml_load_file() function is used to read XML data from a file.
Assume we have an XML file called "note.xml", that looks like this:
The example below shows how to use the simplexml_load_file() function to read XML data from a file:
<?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
$xml=simplexml_load_file("note.xml") or die("Error: Cannot create object"); print_r($xml);
SimpleXMLElement Object ( [to] => Tove [from] => Jani [heading] => Reminder [body] => Don't forget me this weekend! )
PHP SimpleXML - Get Node/Attribute Values
SimpleXML is a PHP extension that allows us to easily manipulate and get XML data.
PHP SimpleXML - Get Node Values
Get the node values from the "note.xml" file:
(无<?xml version="1.0" encoding="utf-8"?>)
<note> <script/> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
Get the node values from the "note.xml" file:
<?php $xml = simplexml_load_file("note.xml") or die("Error: Cannot create object"); echo $xml->to . "<br>"; echo $xml->from . "<br>"; echo $xml->heading . "<br>"; echo $xml->body;
Tove
Jani
Reminder
Don't forget me this weekend!
Assume we have an XML file called "books.xml", that looks like this:
<?xml version="1.0" encoding="utf-8"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en-us">XQuery Kick Start</title> <author>James McGovern</author> <year>2003</year> <price>49.99</price> </book> <book category="WEB"> <title lang="en-us">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
PHP SimpleXML - Get Node Values of Specific Elements
The following example gets the node value of the <title> element in the first and second <book> elements in the "books.xml" file:
<?php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); echo $xml->book[0]->title . "<br>"; echo $xml->book[1]->title;
当books.xml路径下不存在时
Everyday Italian
Harry Potter
PHP SimpleXML - Get Node Values - Loop
The following example loops through all the <book> elements in the "books.xml" file, and gets the node values of the <title>, <author>, <year>, and <price> elements:
<?php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); foreach ($xml->children() as $books) { echo $books->title . ", "; echo $books->author . ", "; echo $books->year . ", "; echo $books->price . "<br>"; }
Everyday Italian, Giada De Laurentiis, 2005, 30.00
Harry Potter, J K. Rowling, 2005, 29.99
XQuery Kick Start, James McGovern, 2003, 49.99
Learning XML, Erik T. Ray, 2003, 39.95
PHP SimpleXML - Get Attribute Values
The following example gets the attribute value of the "category" attribute of the first <book> element and the attribute value of the "lang" attribute of the <title> element in the second <book> element:
<?php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); echo $xml->book[0]['category'] . "<br>"; echo $xml->book[1]->title['lang'];
COOKING
en
PHP SimpleXML - Get Attribute Values - Loop
The following example gets the attribute values of the <title> elements in the "books.xml" file:
<?php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); foreach ($xml->children() as $books) { echo $books->title['lang']; echo "<br>"; }
en
en
en-us
en-us
(有无<?xml version="1.0" encoding="UTF-8"?>都不改变最终输出的结果)
Initializing the XML Expat Parser
We want to initialize the XML Expat Parser in PHP, define some handlers for different XML events, and then parse the XML file.
<?php // Initialize the XML parser $parser = xml_parser_create(); // Function to use at the start of an element function start($parser, $element_name, $element_attrs) { switch ($element_name) { case "NOTE": echo "-- Note --<br>"; break; case "TO": echo "To: "; break; case "FROM": echo "From: "; break; case "HEADING": echo "Heading: "; break; case "BODY": echo "Message: "; } } // Function to use at the end of an element function stop($parser, $element_name) { echo "<br>"; } // Function to use when finding character data function char($parser, $data) { echo $data; } // Specify element handler xml_set_element_handler($parser, "start", "stop"); // Specify data handler xml_set_character_data_handler($parser, "char"); // Open XML file $fp = fopen("note.xml", "r"); // Read data while ($data = fread($fp, 4096)) { xml_parse($parser, $data, feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } // Free the XML parser xml_parser_free($parser);
-- Note --
To: Tove
From: Jani
Heading: Reminder
Message: Don't forget me this weekend!
Example explained:
- Initialize the XML parser with the xml_parser_create() function
- Create functions to use with the different event handlers
- Add the xml_set_element_handler() function to specify which function will be executed when the parser encounters the opening and closing tags
- Add the xml_set_character_data_handler() function to specify which function will execute when the parser encounters character data
- Parse the file "note.xml" with the xml_parse() function
- In case of an error, add xml_error_string() function to convert an XML error to a textual description
- Call the xml_parser_free() function to release the memory allocated with the xml_parser_create() function
<?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); print $xmlDoc->saveXML();
Tove Jani Reminder Don't forget me this weekend!
<?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . " = " . $item->nodeValue . "<br>"; }
#text =
to = Tove
#text =
from = Jani
#text =
heading = Reminder
#text =
body = Don't forget me this weekend!
#text =
https://zh.wikipedia.org/wiki/XML
(w当前看,不严谨,不合时宜!)
XML设计用来传送及携带数据信息,不用来表现或展示数据,HTML语言则用来表现数据,所以XML用途的焦点是它说明数据是什么,以及携带数据信息。
- 丰富文件(Rich Documents)- 自定文件描述并使其更丰富
- 属于文件为主的XML技术应用
- 标记是用来定义一份资料应该如何呈现
- 元数据(Metadata)- 描述其它文件或网络资讯
- 属于资料为主的XML技术应用
- 标记是用来说明一份资料的意义
- 配置文档(Configuration Files)- 描述软件设置的参数
css
XSL 指扩展样式表语言(EXtensible Stylesheet Language)。
万维网联盟开始发展 XSL 的起因是由于对基于 XML 的样式表语言的需求。
http://www.w3school.com.cn/xsl/xsl_languages.asp
XSL
它起始于 XSL,结束于 XSLT、XPath 以及 XSL-FO。
起始于 XSL
XSL 指扩展样式表语言(EXtensible Stylesheet Language)。
万维网联盟 (W3C) 开始发展 XSL 的原因是:存在着对于基于 XML 的样式表语言的需求。
CSS = HTML 样式表
HTML 使用预先定义的标签,标签的意义很容易被理解。
HTML 元素中的 <table> 元素定义表格 - 并且浏览器清楚如何显示它。
向 HTML 元素添加样式是很容易的。通过 CSS,很容易告知浏览器用特定的字体或颜色显示一个元素。
XSL = XML 样式表
XML 不使用预先定义的标签(我们可以使用任何喜欢的标签名),并且这些标签的意义并不都那么容易被理解。
<table> 元素意味着一个 HTML 表格,一件家具,或是别的什么东西 - 浏览器不清楚如何显示它。
XSL 可描述如何来显示 XML 文档!
XSL - 不仅仅是样式表语言
XSL 包括三部分:
- XSLT
- 一种用于转换 XML 文档的语言。
- XPath
- 一种用于在 XML 文档中导航的语言。
- XSL-FO
- 一种用于格式化 XML 文档的语言。
-
XSLT 是一种用于将 XML 文档转换为 XHTML 文档或其他 XML 文档的语言。
XPath 是一种用于在 XML 文档中进行导航的语言。
- cdcatalog_ex2.xsl
-
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited with XML Spy v2007 (http://www.altova.com) --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <tr> <td><xsl:value-of select="catalog/cd/title" /></td> <td><xsl:value-of select="catalog/cd/artist" /></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
cdcatalog_with_ex2.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited with XML Spy v2007 (http://www.altova.com) --> <?xml-stylesheet type="text/xsl" href="cdcatalog_ex2.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd> <cd> <title>Still got the blues</title> <artist>Gary Moore</artist> <country>UK</country> <company>Virgin records</company> <price>10.20</price> <year>1990</year> </cd> <cd> <title>Eros</title> <artist>Eros Ramazzotti</artist> <country>EU</country> <company>BMG</company> <price>9.90</price> <year>1997</year> </cd> <cd> <title>One night only</title> <artist>Bee Gees</artist> <country>UK</country> <company>Polydor</company> <price>10.90</price> <year>1998</year> </cd> <cd> <title>Sylvias Mother</title> <artist>Dr.Hook</artist> <country>UK</country> <company>CBS</company> <price>8.10</price> <year>1973</year> </cd> <cd> <title>Maggie May</title> <artist>Rod Stewart</artist> <country>UK</country> <company>Pickwick</company> <price>8.50</price> <year>1990</year> </cd> <cd> <title>Romanza</title> <artist>Andrea Bocelli</artist> <country>EU</country> <company>Polydor</company> <price>10.80</price> <year>1996</year> </cd> <cd> <title>When a man loves a woman</title> <artist>Percy Sledge</artist> <country>USA</country> <company>Atlantic</company> <price>8.70</price> <year>1987</year> </cd> <cd> <title>Black angel</title> <artist>Savage Rose</artist> <country>EU</country> <company>Mega</company> <price>10.90</price> <year>1995</year> </cd> <cd> <title>1999 Grammy Nominees</title> <artist>Many</artist> <country>USA</country> <company>Grammy</company> <price>10.20</price> <year>1999</year> </cd> <cd> <title>For the good times</title> <artist>Kenny Rogers</artist> <country>UK</country> <company>Mucik Master</company> <price>8.70</price> <year>1995</year> </cd> <cd> <title>Big Willie style</title> <artist>Will Smith</artist> <country>USA</country> <company>Columbia</company> <price>9.90</price> <year>1997</year> </cd> <cd> <title>Tupelo Honey</title> <artist>Van Morrison</artist> <country>UK</country> <company>Polydor</company> <price>8.20</price> <year>1971</year> </cd> <cd> <title>Soulsville</title> <artist>Jorn Hoel</artist> <country>Norway</country> <company>WEA</company> <price>7.90</price> <year>1996</year> </cd> <cd> <title>The very best of</title> <artist>Cat Stevens</artist> <country>UK</country> <company>Island</company> <price>8.90</price> <year>1990</year> </cd> <cd> <title>Stop</title> <artist>Sam Brown</artist> <country>UK</country> <company>A and M</company> <price>8.90</price> <year>1988</year> </cd> <cd> <title>Bridge of Spies</title> <artist>T`Pau</artist> <country>UK</country> <company>Siren</company> <price>7.90</price> <year>1987</year> </cd> <cd> <title>Private Dancer</title> <artist>Tina Turner</artist> <country>UK</country> <company>Capitol</company> <price>8.90</price> <year>1983</year> </cd> <cd> <title>Midt om natten</title> <artist>Kim Larsen</artist> <country>EU</country> <company>Medley</company> <price>7.80</price> <year>1983</year> </cd> <cd> <title>Pavarotti Gala Concert</title> <artist>Luciano Pavarotti</artist> <country>UK</country> <company>DECCA</company> <price>9.90</price> <year>1991</year> </cd> <cd> <title>The dock of the bay</title> <artist>Otis Redding</artist> <country>USA</country> <company>Atlantic</company> <price>7.90</price> <year>1987</year> </cd> <cd> <title>Picture book</title> <artist>Simply Red</artist> <country>EU</country> <company>Elektra</company> <price>7.20</price> <year>1985</year> </cd> <cd> <title>Red</title> <artist>The Communards</artist> <country>UK</country> <company>London</company> <price>7.80</price> <year>1987</year> </cd> <cd> <title>Unchain my heart</title> <artist>Joe Cocker</artist> <country>USA</country> <company>EMI</company> <price>8.20</price> <year>1987</year> </cd> </catalog>