【发布时间】:2020-04-13 11:45:55
【问题描述】:
我无法访问 XML 文件中的一些嵌套数据。我可以使用 Item->ItemID 获取诸如“ItemID”之类的数据,但无法获取“ItemSpecifics”中的数据。
例如,我如何访问 ItemSpecifics 中的颜色或里程?
我已经尝试过 Item->ItemSpecifics->Mileage 和 Item->ItemSpecifics[1]->Color 但没有运气。
这就是 XML 的样子:
<?xml version="1.0" encoding="UTF-8"?>
<GetSingleItemResponse
xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2020-04-13T11:05:22.064Z</Timestamp>
<Ack>Success</Ack>
<Build>E1141_CORE_APILW_19170841_R1</Build>
<Version>1141</Version>
<Item>
<ItemID>283814879195</ItemID>
<EndTime>2020-04-14T13:58:36.000Z</EndTime>
<ViewItemURLForNaturalSearch>https://www.ebay.co.uk/itm/MERCEDES-CL-CL55-Auto-CL55-AMG-Black-Semi-Auto-Petrol-2003-/283814879195</ViewItemURLForNaturalSearch>
<ListingType>LeadGeneration</ListingType>
<Location>Swindon</Location>
<GalleryURL>https://thumbs4.ebaystatic.com/pict/2838148791958080_1.jpg</GalleryURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/XrkAAOSwO5Vd8Qph/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/pasAAOSwJkFd8Qpg/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/5lcAAOSwBi5d8Qph/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/~dYAAOSwK~td8Qph/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/xHsAAOSw3t1d8Qpg/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/60wAAOSwWEdd8Qpg/$_1.JPG?set_id=880000500F</PictureURL>
<PictureURL>https://i.ebayimg.com/00/s/MTEyNVgxNTAw/z/A3cAAOSwhYNd8Qpg/$_1.JPG?set_id=880000500F</PictureURL>
<PrimaryCategoryID>9855</PrimaryCategoryID>
<PrimaryCategoryName>Cars, Motorcycles & Vehicles:Cars:Mercedes-Benz</PrimaryCategoryName>
<BidCount>0</BidCount>
<ConvertedCurrentPrice currencyID="GBP">4495.0</ConvertedCurrentPrice>
<ListingStatus>Active</ListingStatus>
<TimeLeft>P1DT2H53M14S</TimeLeft>
<Title>MERCEDES CL CL55 Auto CL55 AMG Black Semi-Auto Petrol, 2003 </Title>
<ItemSpecifics>
<NameValueList>
<Name>Previous owners</Name>
<Value>4</Value>
</NameValueList>
<NameValueList>
<Name>Colour</Name>
<Value>Black</Value>
</NameValueList>
<NameValueList>
<Name>Mileage</Name>
<Value>146951</Value>
</NameValueList>
<NameValueList>
<Name>Power</Name>
<Value>360</Value>
</NameValueList>
<NameValueList>
<Name>Engine Size</Name>
<Value>5439</Value>
</NameValueList>
<NameValueList>
<Name>Year</Name>
<Value>2003</Value>
</NameValueList>
<NameValueList>
<Name>Manufacturer</Name>
<Value>Mercedes-Benz</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>Other</Value>
</NameValueList>
<NameValueList>
<Name>Body Type</Name>
<Value>Other</Value>
</NameValueList>
<NameValueList>
<Name>Doors</Name>
<Value>2</Value>
</NameValueList>
<NameValueList>
<Name>Seats</Name>
<Value>4</Value>
</NameValueList>
<NameValueList>
<Name>Transmission</Name>
<Value>Semi-Automatic</Value>
</NameValueList>
<NameValueList>
<Name>Fuel</Name>
<Value>Petrol</Value>
</NameValueList>
<NameValueList>
<Name>Reg. Date</Name>
<Value>20030114</Value>
</NameValueList>
<NameValueList>
<Name>MOT Expiry</Name>
<Value>202006</Value>
</NameValueList>
<NameValueList>
<Name>Reg. Mark</Name>
<Value>**52 *** <a target="_JumpPage" href="http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewJumpPageForVehicleHistory&vrm=Uk41MkVWUg%3D%3D&vrm_d=**52 ***">Get the Vehicle Status Report </A><img src="http://pics.ebaystatic.com/aw/pics/uk/motors/vsr_logo_small.gif" width="20" height="20" alt="VSR" align="middle" border="0" ></Value>
</NameValueList>
</ItemSpecifics>
<Country>GB</Country>
<AutoPay>false</AutoPay>
<ConditionID>3000</ConditionID>
<ConditionDisplayName>Used</ConditionDisplayName>
</Item>
</GetSingleItemResponse>
【问题讨论】:
-
里程或颜色是xml值,你不能这样访问它们;要搜索给定标签(此处为“名称”)的某些值,您必须使用 xpath 搜索。有关 xpath 和 SimpleXml,请参阅 PHP 手册