I'm trying to get XML data from a URL. When I print the code below, the variable $name does not print. Any ideas on why the XML data is not being parsed into the $name variable? Thanks in advanced!
$doc = new DOMDocument();
$doc->load(simplexml_load_file("http://api.remix.bestbuy.com/v1/products(name=$new*)?apiKey=API-KEY&sort=salesRankLongTerm.asc"));
## lets read the code block
$records = $doc->getElementsByTagName( "product" );
foreach( $records as $record )
{
## parse the name
$name = $record->getElementsByTagName( "name" );
$name = $name->item(0)->nodeValue;
echo $records;
}
Piece of XML code from browser:
<product>
<sku>6238297</sku>
<productId>1218721416338</productId>
<name>Apple® - MacBook Air® - 13.3" Display - 4GB Memory - 128GB Flash Storage</name>
<source>bestbuy</source>
<type>HardGood</type>
<startDate>2013-06-11</startDate>
<new>false</new>
<active>true</active>
<lowPriceGuarantee>true</lowPriceGuarantee>
<activeUpdateDate>2014-03-05T23:36:23</activeUpdateDate>
<regularPrice>1099.99</regularPrice>
<salePrice>1099.99</salePrice>
<onSale>false</onSale>
<planPrice/>
<priceWithPlan/>
<priceRestriction/>
<priceUpdateDate>2014-03-30T00:11:15</priceUpdateDate>
<digital>false</digital>
<preowned>false</preowned>
<carrierPlans/>
<technologyCode/>
<carrierModelNumber/>
<earlyTerminationFees/>
<outletCenter/>
<secondaryMarket/>
<frequentlyPurchasedWith/>
<accessories>
<sku>9634885</sku>
<sku>1019306</sku>
<sku>5856129</sku>
<sku>7016136</sku>
<sku>7077111</sku>
<sku>7016127</sku>
</accessories>
<relatedProducts>
<sku>1307511053</sku>
<sku>1307511077</sku>
<sku>1306954028</sku>
<sku>1306862453</sku>
<sku>1307510025</sku>
</relatedProducts>
<techSupportPlans>
<sku>1853259</sku>
</techSupportPlans>
<salesRankShortTerm>294</salesRankShortTerm>
<salesRankMediumTerm>269</salesRankMediumTerm>
<salesRankLongTerm>285</salesRankLongTerm>
<bestSellingRank>297</bestSellingRank>
<url>http://www.bestbuy.com/site/apple-macbook-air-13-3-display-4gb-memory-128gb-flash-storage/6238297.p?id=1218721416338&skuId=6238297&cmp=RMX&ky=2epk1kYlBfccbc5Dqglj3cTQUWJ0mBN4C</url>
<spin360Url/>
<mobileUrl>http://m.bestbuy.com/r/1218721416338/6238297/</mobileUrl>
<affiliateUrl/>
<addToCartUrl>http://www.bestbuy.com/site/olspage.jsp?id=pcmcat152200050035&type=category&cmp=RMX&ky=2epk1kYlBfccbc5Dqglj3cTQUWJ0mBN4C&qvsids=6238297</addToCartUrl>
<affiliateAddToCartUrl/>
<linkShareAffiliateUrl/>
<linkShareAffiliateAddToCartUrl/>
<upc>885909630882</upc>
<productTemplate>Notebook_Computers</productTemplate>
<categoryPath>
<category>
<id>cat00000</id>
<name>Best Buy</name>
</category>
<category>
<id>abcat0500000</id>
<name>Computers & Tablets</name>
</category>
<category>
<id>abcat0502000</id>
<name>Laptops</name>
</category>
<category>
<id>pcmcat247400050001</id>
<name>MacBooks</name>
</category>
</categoryPath>
<lists/>
<customerReviewCount>922</customerReviewCount>
<customerReviewAverage>4.8</customerReviewAverage>
<format/>
<freeShipping>true</freeShipping>
<freeShippingEligible>true</freeShippingEligible>
<inStoreAvailability>true</inStoreAvailability>
<inStoreAvailabilityText>Store Pickup:</inStoreAvailabilityText>
<inStoreAvailabilityUpdateDate>2014-03-05T23:36:23</inStoreAvailabilityUpdateDate>
<itemUpdateDate>2014-03-31T09:13:14</itemUpdateDate>
<onlineAvailability>true</onlineAvailability>
<onlineAvailabilityText>Shipping: Usually leaves our warehouse in 1 business day</onlineAvailabilityText>
<onlineAvailabilityUpdateDate>2014-03-05T23:36:23</onlineAvailabilityUpdateDate>
<releaseDate>2013-06-20</releaseDate>
<shippingCost>0.00</shippingCost>
<shipping>
<ground>0.00</ground>
<secondDay>12.99</secondDay>
<nextDay>26.99</nextDay>
<vendorDelivery/>
</shipping>
<specialOrder>false</specialOrder>
<shortDescription>4th Gen Intel® Core™ i5 processor; 13.3" display; 4GB memory; 128GB flash storageSpecial features: BluetoothDVD/CD drive not included</shortDescription>
<class>MOBILE COMPUTING</class>
<classId>140</classId>
<subclass>APPLE</subclass>
<subclassId>5075</subclassId>
<department>COMPUTERS</department>
<departmentId>6</departmentId>
<buybackPlans/>
<protectionPlans>
<protectionPlan>
<sku>9977898</sku>
<name>3-Year Accidental Protection Plan - Geek Squad</name>
<productId>1218228675955</productId>
<type>PSP-PRP</type>
<term>3YR</term>
<regularPrice>499.98</regularPrice>
<salePrice>499.98</salePrice>
</protectionPlan>
<protectionPlan>
<sku>9975645</sku>
<name>2-Year Accidental Protection Plan - Geek Squad</name>
<productId>1218228680268</productId>
<type>PSP-PRP</type>
<term>2YR</term>
<regularPrice>339.99</regularPrice>
<salePrice>339.99</salePrice>
</protectionPlan>
<protectionPlan>
<sku>9978139</sku>
<name>1-Year Accidental Protection Plan - Geek Squad</name>
<productId>1218228674882</productId>
<type>PSP-PRP</type>
<term>1YR</term>
<regularPrice>199.99</regularPrice>
<salePrice>199.99</salePrice>
</protectionPlan>
</protectionPlans>
<productFamilies/>
<description/>
<manufacturer>Apple®</manufacturer>
<modelNumber>MD760LL/A</modelNumber>
<image>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297_sc.jpg</image>
<largeFrontImage>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297_sa.jpg</largeFrontImage>
<mediumImage>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297fp.gif</mediumImage>
<thumbnailImage>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297_s.gif</thumbnailImage>
<largeImage>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297_sb.jpg</largeImage>
<alternateViewsImage>http://images.bestbuy.com/BestBuy_US/images/products/6238/6238297cv1a.jpg</alternateViewsImage>
<angleImage/>
<backViewImage/>
<energyGuideImage/>
<leftViewImage/>
<accessoriesImage/>
<remoteControlImage/>
<rightViewImage/>
<topViewImage/>
<condition>New</condition>
<inStorePickup>true</inStorePickup>
<friendsAndFamilyPickup>true</friendsAndFamilyPickup>
<homeDelivery>false</homeDelivery>
<quantityLimit>1</quantityLimit>
<fulfilledBy>BestBuy.com</fulfilledBy>
<bundledIn/>
<color/>
<depth>8.94"</depth>
<dollarSavings>0.00</dollarSavings>
<percentSavings>0.0</percentSavings>
<tradeInValue/>
<height>0.11"–0.68"</height>
<orderable>Available</orderable>
<weight>2.96 lbs.</weight>
<shippingWeight>6.45</shippingWeight>
<width>12.8"</width>
<warrantyLabor>1 year limited</warrantyLabor>
<warrantyParts>1 year limited</warrantyParts>
<longDescription>The new MacBook Air features 4th Gen Intel® Core™ processors with faster graphics, all-day battery life,1 and even faster flash storage.2 It's thin, light, and durable enough to take everywhere you go — and powerful enough to do everything once you get there.</longDescription>
<includedItemList/>
<marketplace>false</marketplace>
<listingId/>
<sellerId/>
<shippingRestrictions/>
<bluRayPlayer>false</bluRayPlayer>
<bluetoothEnabled>true</bluetoothEnabled>
<displayType>1440 x 900 pixel LED-backlit glossy</displayType>
<energyStarQualified>true</energyStarQualified>
<screenSizeIn>13.3</screenSizeIn>
</product>