这是xml的片段,它是我从未见过的格式,对于我的生活,我无法弄清楚如何将其解析为在网站上看起来不错的东西。这是xml。这是shopping.com api上搜索查询的结果。
object(SimpleXMLElement)#14 (11) {
["@attributes"]=>
array(1) {
["id"]=>
string(9) "101677489"
}
["name"]=>
string(26) "Nikon D3100 Digital Camera"
["shortDescription"]=>
string(87) "14.2 Megapixel, SLR Camera, 3 in. LCD Screen, With High Definition Video, Weight: 1 lb."
["fullDescription"]=>
string(829) "The Nikon D3100 digital SLR camera speaks to the growing ranks of enthusiastic D-SLR users and aspiring photographers by providing an easy-to-use and affordable entrance to the world of Nikon D-SLR’s. The 14.2-megapixel D3100 has powerful features, such as the enhanced Guide Mode that makes it easy to unleash creative potential and capture memories with still images and full HD video. Like having a personal photo tutor at your fingertips, this unique feature provides a simple graphical interface on the camera’s LCD that guides users by suggesting and/or adjusting camera settings to achieve the desired end result images. The D3100 is also the world’s first D-SLR to introduce full time auto focus (AF) in Live View and D-Movie mode to effortlessly achieve the critical focus needed when shooting Full HD 1080p video."
["images"]=>
object(SimpleXMLElement)#4 (1) {
["image"]=>
array(5) {
[0]=>
object(SimpleXMLElement)#13 (2) {
["@attributes"]=>
array(3) {
["available"]=>
string(4) "true"
["height"]=>
string(3) "100"
["width"]=>
string(3) "100"
}
["sourceURL"]=>
string(131) "http://di1.shopping.com/images/pi/93/bc/04/101677489-100x100-0-0.jpg?p=p2.6566ad68b022f6260efc&a=2&c=1&l=7000610&t=110528211343&r=2"
}
[1]=>
object(SimpleXMLElement)#5 (2) {
["@attributes"]=>
array(3) {
["available"]=>
string(4) "true"
["height"]=>
string(3) "200"
["width"]=>
string(3) "200"
}
["sourceURL"]=>
string(131) "http://di1.shopping.com/images/pi/93/bc/04/101677489-200x200-0-0.jpg?p=p2.6566ad68b022f6260efc&a=2&c=1&l=7000610&t=110528211343&r=2"
}
[2]=>
object(SimpleXMLElement)#12 (2) {
["@attributes"]=>
array(3) {
["available"]=>
string(4) "true"
["height"]=>
string(3) "300"
["width"]=>
string(3) "300"
}
["sourceURL"]=>
string(131) "http://di1.shopping.com/images/pi/93/bc/04/101677489-300x300-0-0.jpg?p=p2.6566ad68b022f6260efc&a=2&c=1&l=7000610&t=110528211343&r=2"
}
[3]=>
object(SimpleXMLElement)#11 (2) {
["@attributes"]=>
array(3) {
["available"]=>
string(4) "true"
["height"]=>
string(3) "400"
["width"]=>
string(3) "400"
}
["sourceURL"]=>
string(131) "http://di1.shopping.com/images/pi/93/bc/04/101677489-400x400-0-0.jpg?p=p2.6566ad68b022f6260efc&a=2&c=1&l=7000610&t=110528211343&r=2"
}
[4]=>
object(SimpleXMLElement)#10 (2) {
["@attributes"]=>
array(3) {
["available"]=>
string(4) "true"
["height"]=>
string(3) "500"
["width"]=>
string(3) "606"
}
["sourceURL"]=>
string(131) "http://di1.shopping.com/images/pi/93/bc/04/101677489-606x500-0-0.jpg?p=p2.6566ad68b022f6260efc&a=2&c=1&l=7000610&t=110528211343&r=2"
}
}
}
["rating"]=>
object(SimpleXMLElement)#7 (4) {
["reviewCount"]=>
string(1) "5"
["rating"]=>
string(4) "5.00"
["ratingImage"]=>
object(SimpleXMLElement)#9 (2) {
["@attributes"]=>
array(2) {
["height"]=>
string(2) "18"
["width"]=>
string(2) "91"
}
["sourceURL"]=>
string(48) "http://img.shopping.com/sc/pr/sdc_stars_sm_5.gif"
}
["reviewURL"]=>
string(61) "http://www.shopping.com/Nikon-D3100/reviews~linkin_id-7000610"
}
["minPrice"]=>
string(6) "519.00"
["maxPrice"]=>
string(6) "712.00"
["productOffersURL"]=>
string(60) "http://www.shopping.com/Nikon-D3100/prices~linkin_id-7000610"
["productSpecsURL"]=>
string(58) "http://www.shopping.com/Nikon-D3100/info~linkin_id-7000610"
["offers"]=>
object(SimpleXMLElement)#6 (1) {
["@attributes"]=>
array(3) {
["matchedOfferCount"]=>
string(2) "10"
["pageNumber"]=>
string(1) "1"
["returnedOfferCount"]=>
string(1) "0"
}
}
有什么想法吗?我已经尝试过以下代码,但它没有改变任何内容。
foreach( $xml->categories->category->items->product as $product )
{
var_dump($product);
}
foreach( $xml->categories->category->items->offer as $offer )
{
var_dump($offer);
}
答案 0 :(得分:0)
尝试类似:
foreach( $xml->categories->category->items->product as $product )
{
echo "{$product->name} from {$product->minPrice} to {$product->maxPrice}\n";
}