Selecting / Filtering XML Element with XPath - php

here is my amazon mws api responce
<?xml version="1.0"?>
<GetMyPriceForSKUResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMyPriceForSKUResult SellerSKU="ds-tru-6sss" status="Success">
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>Assssssss</MarketplaceId>
<ASIN>sss</ASIN>
</MarketplaceASIN>
<SKUIdentifier>
<MarketplaceId>Afasrfd</MarketplaceId>
<SellerId>ssssss</SellerId>
<SellerSKU>dssss</SellerSKU>
</SKUIdentifier>
</Identifiers>
<Offers>
<Offer>
<BuyingPrice>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>12.49</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>12.49</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</BuyingPrice>
<RegularPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>12.49</Amount>
</RegularPrice>
<FulfillmentChannel>MERCHANT</FulfillmentChannel>
<ItemCondition>New</ItemCondition>
<ItemSubCondition>New</ItemSubCondition>
<SellerId>Aadada</SellerId>
<SellerSKU>ssss</SellerSKU>
</Offer>
<Offer>
<BuyingPrice>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>1000.00</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>1000.00</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</BuyingPrice>
<RegularPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>1000.00</Amount>
</RegularPrice>
<FulfillmentChannel>MERCHANT</FulfillmentChannel>
<ItemCondition>New</ItemCondition>
<ItemSubCondition>New</ItemSubCondition>
<SellerId>ssss</SellerId>
<SellerSKU>sss</SellerSKU>
</Offer>
</Offers>
</Product>
</GetMyPriceForSKUResult>
<ResponseMetadata>
<RequestId>e0ef1c2c-4f35-4316-8629-faadadd</RequestId>
</ResponseMetadata>
</GetMyPriceForSKUResponse>
and to select amount (12.49) from
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>12.49</Amount>
</ListingPrice>
I am trying ,
// from curl
$result = curl_exec ($ch);
$xmldoc = new DOMDocument();
$xmldoc->load($result);
$xpathvar = new Domxpath($xmldoc);
$queryResult = $xpathvar->query('/Amount');
foreach($queryResult as $result){
echo $result;
}
I am expecting more then one value for this, but I am getting none at all.
Sorry, I am not good at XPath, can somebody guide me?

Currently I found errors in your code:
First: Use two // to select an element regardless of where it is located in the xml tree.
$queryResult = $xpathvar->query('//Amount');
Second: thanks #Ranon. You'll take care of the documents xml namespace:
// Register Namespace mws
$xpathvar->registerNamespace("mws", 'http://mws.amazonservices.com/schema/Products/2011-10-01');
... and use it, means:
$queryResult = $xpathvar->query('//mws:Amount');
Third: If you want to select the text node (between the <amount> nodes) you should use:
$queryResult = $xpathvar->query('//mws:Amount/text()');
Otherwise you can select the parent element <Amount> (as you already doing) and retrieve the value with PHP. Then you have to change your code to:
$queryResult = $xpathvar->query('//mws:Amount');
foreach($queryResult as $result){
echo $result->nodeValue; // echo the node value, not the node 'itself'
}
Fourth: Also note another error in your code. When you create a DOMDocument from an xml string you'll have to use:
$document->loadXML($result);
Fifth: You told that you want to retrieve the <Amount> elements form inside <ListingPrice> elements. Note that there are also <Amount> elements inside <RegularPrice> elements. So it does matter where the <Amount> element is located in tree. Use the following query to obtain only listing price amounts:
$queryResult = $xpathvar->query('//mws:ListingPrice/mws:Amount');

Amazon returns XML using a namespace which you have to declare and use.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// from curl
$result = curl_exec($ch);
$xmldoc = new DOMDocument();
$xmldoc->loadXML($result);
$xpathvar = new Domxpath($xmldoc);
// Register Namespace mws
$xpathvar->registerNamespace("mws", 'http://mws.amazonservices.com/schema/Products/2011-10-01');
// Query using namespace mws
$queryResult = $xpathvar->query('//mws:Amount');
foreach($queryResult as $result){
echo $result->nodeValue;
}
I selected the namespace identifier mws arbitrarily from the subdomain, you can choose another if you want.
I corrected some other errors in the code found by #hek2mgl.

The XPath expression is wrong. You need '//Amount' to select all the "Amount" elements

Related

Only able to select first node when there is a default namespace in xpath

I've been having problems querying an xml file that contains default namespaces and it's been a nightmare.
I've been able to select the first node after declaring a namespace but anything that follows gets ignored.
$str = '<?xml version="1.0"?>
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetLowestOfferListingsForASINResult>
<Product>
<LowestOfferListings>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>Used</ItemCondition>
<ItemSubcondition>Good</ItemSubcondition>
<FulfillmentChannel>Merchant</FulfillmentChannel>
<ShipsDomestically>Unknown</ShipsDomestically>
<ShippingTime>
<Max>0-2 days</Max>
</ShippingTime>
<SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating>
</Qualifiers>
<NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered>
<SellerFeedbackCount>83352</SellerFeedbackCount>
<Price>
<LandedPrice>
<CurrencyCode>GBP</CurrencyCode>
<Amount>7.40</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>GBP</CurrencyCode>
<Amount>4.60</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>GBP</CurrencyCode>
<Amount>2.80</Amount>
</Shipping>
</Price>
<MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice>
</LowestOfferListing>
</LowestOfferListings>
</Product>
</GetLowestOfferListingsForASINResult>
</GetLowestOfferListingsForASINResponse>';
$xml = new SimpleXMLElement($str);
$xml->registerXPathNamespace('c', 'http://mws.amazonservices.com/schema/Products/2011-10-01');
print_r($xml->xpath("c:GetLowestOfferListingsForASINResult")); //works
print_r($xml->xpath("c:GetLowestOfferListingsForASINResult/Product")); //not working
print_r($xml->xpath("c:GetLowestOfferListingsForASINResult//Product")); //not working
Xpath has no automatic default namespace (it's always the null-namespace), so you need to explicitly use the "c:" prefix with all element names:
c:GetLowestOfferListingsForASINResult/c:Product
^^
c:GetLowestOfferListingsForASINResult//c:Product
^^
if you're interested in the details why this is the case, there is the following existing Q&A on this website:
XPath in SimpleXML for default namespaces without needing prefixes

simplexml parser php iteration

I cannot figure out how does this thing work. I followed Instruction from PHP Doc.
Here is my code:
$xmlfile = simplexml_load_file($xmlurl) or die("Cannon get.");
The file contains following schema:
<PriceResult>
<QueryStatus>
</QueryStatus>
<InputData>
</InputData>
<Producers/>
<Prices>
<Price>
</Price>
<Price>
<PartId>13580448730</PartId>
<BrandId>11</BrandId>
<Brand>BERU</Brand>
<PartNumber>Z226</PartNumber>
<PartNumberShort>Z226</PartNumberShort>
<PartDescriptionRus/>
<Price>8.90</Price>
<Currency>EUR</Currency>
<Quantity>0</Quantity>
<QuantityType>EQUAL</QuantityType>
<PriceLogo>GLIR</PriceLogo><Weight/>
<PriceDescrShort>Европейский поставщик запчастей</PriceDescrShort>
<PriceDescrLong>Европейский поставщик запчастей</PriceDescrLong>
<DeliveryType>LOCAL</DeliveryType>
<DeliveryDays>17</DeliveryDays>
<PriceChangeDate>2015-01-05 10:27:05</PriceChangeDate>
<DamagedFlag>N</DamagedFlag>
<UsedFlag>N</UsedFlag>
<OriginalFlag>N</OriginalFlag>
<OldPartNumberFlag>N</OldPartNumberFlag>
<Group>0</Group><GroupDescr/>
</Price>
<Price>
</Price>
<Price>
</Price>
</PriceResult>
I did that before, but now I forgot. So how could I iterate XML through Price in Prices to be able get data like this:
foreach ($xmlfile->children() as $item){
print($item->BrandId);
}
and Ill get all the brands, or $item->PartId - all the part? e.t.c to all
$xmlfile = simplexml_load_file($xmlurl) or die("Cannon get.");
Then
$xxx= $xmlfile->xxx;
$yyy = $xmlfile->yyy;
$zzz = $xmlfile->zzz;
After all, it's more simple to show data like this
echo $xxx;
And where is your "->children() " ?

XML array - Trying to get property of non-object foreach() error - Codeigniter

I am runing scrip which bring order details from xml array. issue is every time the script runs i am getting foreach() error. I am thing this is htmlentities in Title but not sure. can please you help?
$products='';
$xml=simplexml_load_string($response);
$temp_arr=array();
foreach($xml->ListOrderItemsResult->OrderItems->OrderItem as $product)
{
$temp_arr[]=array('item'=>(string)$product->Title,'quantity'=>(string)$product->QuantityOrdered,'order_item_code'=>(string)$product->OrderItemId,'sku'=>(string)$product->SellerSKU);
}
return $temp_arr;
}
Array is correct i am check the array bring all data there is no empty value.
I am getting 2 error on same line - foreach($xml->ListOrderItemsResult->OrderItems->OrderItem as $product)
Trying to get property of non-object
Invalid argument supplied for foreach()
XML
<?xml version="1.0"?>
<ListOrderItemsResponse xmlns="https://mws.amazonservices.com/Orders/2011-01-01">
<ListOrderItemsResult>
<OrderItems>
<OrderItem>
<OrderItemId>32080774637267</OrderItemId>
<GiftWrapPrice>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapPrice>
<QuantityOrdered>1</QuantityOrdered>
<GiftWrapTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapTax>
<SellerSKU>KS-MQOX-EUQ5</SellerSKU>
<Title>SINGLE DOUBLE & KING SIZE FITTED SHEETS Pillow cases BESPOKE BEDDING (Grey, pillowcases Standard 19"x29")</Title>
<ShippingTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingTax>
<ShippingPrice>
<Amount>2.95</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingPrice>
<ItemTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemTax>
<ItemPrice>
<Amount>2.99</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemPrice>
<PromotionDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</PromotionDiscount>
<ConditionId>New</ConditionId>
<ASIN>B00AFB1XH8</ASIN>
<QuantityShipped>0</QuantityShipped>
<ConditionSubtypeId>New</ConditionSubtypeId>
<ConditionNote>Brand New</ConditionNote>
<ShippingDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingDiscount>
</OrderItem>
</OrderItems>
<AmazonOrderId>026-3622751-4319550</AmazonOrderId>
</ListOrderItemsResult>
<ResponseMetadata>
<RequestId>42f09535-70e7-4a28-8413-cc439c42c030</RequestId>
</ResponseMetadata>
</ListOrderItemsResponse>
this should work i tested with your xml
foreach ($xml->ListOrderItemsResult->OrderItems as $items) {
foreach( $items->OrderItem as $orderitem ){
echo 'test id is' . $orderitem->OrderItemId ;
}
}
There can be more then one group of Order Items, and each group can contain more then one item. You could also do something like this for testing
echo $xml->ListOrderItemsResult->OrderItems->OrderItem[0]->OrderItemId ;
and always check out the xml structure like
echo '<pre>' ;
print_r($xml);
echo '</pre>' ;
this works for me
<?php
$xml = '<?xml version="1.0"?>
<ListOrderItemsResponse xmlns="https://mws.amazonservices.com/Orders/2011-01-01">
<ListOrderItemsResult>
<OrderItems>
<OrderItem>
<OrderItemId>32080774637267</OrderItemId>
<GiftWrapPrice>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapPrice>
<QuantityOrdered>1</QuantityOrdered>
<GiftWrapTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</GiftWrapTax>
<SellerSKU>KS-MQOX-EUQ5</SellerSKU>
<Title>SINGLE DOUBLE & KING SIZE FITTED SHEETS Pillow cases BESPOKE BEDDING (Grey, pillowcases Standard 19"x29")</Title>
<ShippingTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingTax>
<ShippingPrice>
<Amount>2.95</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingPrice>
<ItemTax>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemTax>
<ItemPrice>
<Amount>2.99</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ItemPrice>
<PromotionDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</PromotionDiscount>
<ConditionId>New</ConditionId>
<ASIN>B00AFB1XH8</ASIN>
<QuantityShipped>0</QuantityShipped>
<ConditionSubtypeId>New</ConditionSubtypeId>
<ConditionNote>Brand New</ConditionNote>
<ShippingDiscount>
<Amount>0.00</Amount>
<CurrencyCode>GBP</CurrencyCode>
</ShippingDiscount>
</OrderItem>
</OrderItems>
<AmazonOrderId>026-3622751-4319550</AmazonOrderId>
</ListOrderItemsResult>
<ResponseMetadata>
<RequestId>42f09535-70e7-4a28-8413-cc439c42c030</RequestId>
</ResponseMetadata>
</ListOrderItemsResponse>';
$list = new SimpleXMLElement($xml);
echo $list->ListOrderItemsResult->OrderItems->OrderItem->OrderItemId;
?>

XML parser using shopify webhooked line-items

I am using shopify webhook to update my sql server's 'qty' field when order updated, below is my php code
?php
$xmlData = fopen('php://input' , 'rb');
while (!feof($xmlData)) { $xmlString .= fread($xmlData, 4096); }
fclose($xmlData);
$xml = new SimplexmlElement($xmlString);
file_put_contents('orders/order' . '.xml', $xmlString);
$dom = new DomDocument();
$dom->load('orders/order.xml');
$itemList = $dom->getElementsByTagName('line-item');
foreach($itemList as $item) {
$sku='';
$qty='';
foreach($item->childNodes as $child) {
if ($child->localName == 'sku') {
$sku = $child->textContent;
}
if ($child->localName == 'quantity') {
$qty = $child->textContent;
}
}
mysql_connect ("?????????????????????????");
mysql_select_db("??????????");
$query = "UPDATE xcart_categories SET product_count = product_count - $qty WHERE description='$sku';";
mysql_query($query);
}
and below is xml file i am getting from shopify webhook
<?xml version="1.0" encoding="UTF-8"?>
<order>
<buyer-accepts-marketing type="boolean">true</buyer-accepts-marketing>
<closed-at type="datetime" nil="true"></closed-at>
<currency>USD</currency>
<email>yeongju_l#yahoo.com</email>
<financial-status>pending</financial-status>
<fulfillment-status>fulfilled</fulfillment-status>
<gateway>Local Pick-Up</gateway>
<id type="integer">140303247</id>
<name>#1012</name>
<note></note>
<number type="integer">12</number>
<subtotal-price type="decimal">0.2</subtotal-price>
<taxes-included type="boolean">false</taxes-included>
<total-discounts type="decimal">0.0</total-discounts>
<total-line-items-price type="decimal">0.2</total-line-items-price>
<total-price type="decimal">0.2</total-price>
<total-price-usd type="decimal">0.2</total-price-usd>
<total-tax type="decimal">0.0</total-tax>
<total-weight type="integer">0</total-weight>
<updated-at type="datetime">2012-09-16T21:20:07-04:00</updated-at>
<created-at type="datetime">2012-09-16T21:08:30-04:00</created-at>
<token>dcf523d93c68159c15a7c8d1fabbee07</token>
<landing-site>/products/test</landing-site>
<referring-site></referring-site>
<cancelled-at type="datetime" nil="true"></cancelled-at>
<cancel-reason nil="true"></cancel-reason>
<cart-token>a9a7bc5d8103f6a3bb45e827f0cb8928</cart-token>
<browser-ip nil="true"></browser-ip>
<landing-site-ref nil="true"></landing-site-ref>
<order-number type="integer">1012</order-number>
<discount-codes type="array"/>
<note-attributes type="array">
</note-attributes>
<processing-method>manual</processing-method>
<line-items type="array">
<line-item>
<id type="integer">228531213</id>
<requires-shipping type="boolean">false</requires-shipping>
<fulfillment-service>manual</fulfillment-service>
<grams type="integer">0</grams>
<price type="decimal">0.2</price>
<quantity type="integer">1</quantity>
<sku>1234567</sku>
<title>test</title>
<product-id type="integer">104663831</product-id>
<variant-id type="integer">240660979</variant-id>
<vendor>5 Second</vendor>
<variant-title nil="true"></variant-title>
<fulfillment-status>fulfilled</fulfillment-status>
<name>test</name>
<variant-inventory-management></variant-inventory-management>
<properties type="array">
</properties>
</line-item>
</line-items>
<shipping-lines type="array"/>
<tax-lines type="array">
<tax-line>
<title>NY State Tax</title>
<price type="decimal">0.0</price>
<rate type="float">0.04</rate>
</tax-line>
<tax-line>
<title>Queens County Tax</title>
<price type="decimal">0.0</price>
<rate type="float">0.04875</rate>
</tax-line>
</tax-lines>
<billing-address>
<first-name>Yeongju</first-name>
<last-name>Lee</last-name>
<address1>14809 northern blvd</address1>
<address2></address2>
<city>Flushing</city>
<company></company>
<country>United States</country>
<phone></phone>
<province>New York</province>
<zip>11354</zip>
<latitude type="decimal">40.76529</latitude>
<longitude type="decimal">-73.81831</longitude>
<name>Yeongju Lee</name>
<country-code>US</country-code>
<province-code>NY</province-code>
</billing-address>
<fulfillments type="array">
<fulfillment>
<id type="integer">67712419</id>
<order-id type="integer">140303247</order-id>
<created-at type="datetime">2012-09-16T21:20:07-04:00</created-at>
<updated-at type="datetime">2012-09-16T21:20:07-04:00</updated-at>
<tracking-number nil="true"></tracking-number>
<tracking-company nil="true"></tracking-company>
<status>success</status>
<service>manual</service>
<tracking-url>http://www.google.com/search?q=</tracking-url>
<receipt>
</receipt>
<line-items type="array">
<line-item>
<id type="integer">228531213</id>
<requires-shipping type="boolean">false</requires-shipping>
<fulfillment-service>manual</fulfillment-service>
<grams type="integer">0</grams>
<price type="decimal">0.2</price>
<quantity type="integer">1</quantity>
<sku>1234567</sku>
<title>test</title>
<product-id type="integer">104663831</product-id>
<variant-id type="integer">240660979</variant-id>
<vendor>5 Second</vendor>
<variant-title nil="true"></variant-title>
<fulfillment-status>fulfilled</fulfillment-status>
<name>test</name>
<variant-inventory-management></variant-inventory-management>
<properties type="array">
</properties>
</line-item>
</line-items>
</fulfillment>
</fulfillments>
<customer>
<id type="integer">96489088</id>
<email>yeongju_l#yahoo.com</email>
<accepts-marketing type="boolean">true</accepts-marketing>
<first-name>Yeongju</first-name>
<last-name>Lee</last-name>
<orders-count type="integer">12</orders-count>
<total-spent type="decimal">16.26</total-spent>
<note nil="true"></note>
<created-at type="datetime">2012-08-17T11:31:50-04:00</created-at>
<updated-at type="datetime">2012-09-16T21:20:07-04:00</updated-at>
<state>enabled</state>
<last-order-id type="integer">140303509</last-order-id>
<tags>C</tags>
<last-order-name>#1013</last-order-name>
</customer>
like you see i got two sku and qty because of duplicated line-item so for example when customer order one "product name - test in this case i got "-2" quantity update in my sql server sku test field , but when i am using webhook event when order creation it worked i mean i see only one line item but all the other cases(when order updated, when order payment, when order fullfillment..) show me duplicated line item even there is only one item ordered
i think i am parsing my XML badly
anyone who can teach me correct code to pull 'line items' from the first line-items node i will really appreciate it! Thanks..again
You're doing a lot of redundant steps to parse your XML there. You don't need to save the data into a file before processing it, and you have a stray call to SimpleXML that you're not using. All you need is this:
$xmlString = file_get_contents('php://input');
$dom = new DomDocument();
$dom->loadXML($xmlString);
After that, your parsing logic looks fine but you are only ever running one SQL query, with one SKU in it.
Inside your foreach loop, you define the variables $sku and $qty, but you don't do anything with them inside the loop. So next time round the loop, you will over-write their values, and nothing will ever know about the old values.
There are few ways to do this:
run SQL inside the loop (not very efficient)
build up an array of SKUs and quantities ($sku[] = ...; $qty[] = ...;) and then build your SQL from these arrays
slightly tidier, build a single array with the SKU-quantity pairs as nested arrays ($sku_list[] = array('sku' => ..., 'qty' => ...))
build your SQL string progressively inside the loop ($sql .= '...') and execute it once at the end

extract data from an xml file using php

I know this has been asked before, and I have tried a few of the suggestions, but I am not getting the information from the XML file. I need to get the number of sellers (OfferListingCount condition="Any")from an xml file. Here is the XML:
<?xml version="1.0"?>
<GetCompetitivePricingForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetCompetitivePricingForASINResult ASIN="0312479743" status="Success">
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>0312479743</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="false" condition="Used" subcondition="Good">
<CompetitivePriceId>2</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>36.23</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>36.23</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
</CompetitivePrice>
</CompetitivePrices>
<NumberOfOfferListings>
<OfferListingCount condition="Any">34</OfferListingCount>
<OfferListingCount condition="Used">29</OfferListingCount>
<OfferListingCount condition="New">5</OfferListingCount>
</NumberOfOfferListings>
Here is my UPDATED code for Php:
$priceComp_xml = amazonCompPrice_xml($asin);
$compPricing = $priceComp_xml->xpath('/OfferListingCount[#condition="Any"]');
$priceComp_xml returns the information from the xml file, and I am trying to use the next line to get the information I need. When I run the code, get an empty array.
How do I get this information?
http://php.net/manual/en/function.simplexml-load-file.php
$xml = simplexml_load_file($xml_file);
$output = array();
foreach ($xml as $row => $item_data)
{
// Attributes
$attributes = $item_data->attributes();
Load it up, get the attributes.

Categories