无法从 eBay API 检索嵌套信息
我将 Linq to XML 与 eBay API 一起使用,但无法从返回的 XML 中检索基本信息。我已经尝试了 from x in y select z
等的每种组合,但没有运气。
我正在加载数据
var xml = XDocument.Load ("http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=***MY-KEY-OBSCURED**&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=yamaha&paginationInput.entriesPerPage=1&paginationInput.pageNumber=1");
,并且根据控制台和 LINQPad 返回以下 XML。
<findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services"> <ack>Success</ack> <version>1.11.0</version> <timestamp>2011-09-04T12:15:10.595Z</timestamp> <searchResult count="1">
<item>
<itemId>220841819907</itemId>
<title>YAMAHA RX-V592 SURROUND SOUND RECEIVER</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>14981</categoryId>
<categoryName>Receivers</categoryName>
</primaryCategory>
<galleryURL>http://thumbs4.ebaystatic.com/pict/2208418199074040_1.jpg</galleryURL>
<viewItemURL>http://www.ebay.com/itm/YAMAHA-RX-V592-SURROUND-SOUND-RECEIVER-/220841819907?pt=Receivers_Tuners</viewItemURL>
<productId type="ReferenceID">46568009</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>false</autoPay>
<postalCode>76638</postalCode>
<location>Crawford,TX,USA</location>
<country>US</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">22.0</shippingServiceCost>
<shippingType>Flat</shippingType>
<expeditedShipping>false</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>3</handlingTime>
<shipToLocations>US</shipToLocations>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">51.0</currentPrice>
<convertedCurrentPrice currencyId="USD">51.0</convertedCurrentPrice>
<bidCount>13</bidCount>
<sellingState>Active</sellingState>
<timeLeft>P0DT0H18M17S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2011-08-28T12:33:27.000Z</startTime>
<endTime>2011-09-04T12:33:27.000Z</endTime>
<listingType>Auction</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>false</returnsAccepted>
<condition>
<conditionId>3000</conditionId>
<conditionDisplayName>Used</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
</item> </searchResult> <paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>1</entriesPerPage>
<totalPages>819204</totalPages>
<totalEntries>819204</totalEntries> </paginationOutput> <itemSearchURL>http://www.ebay.com/sch/i.html?_nkw=yamaha&_ddo=1&_ipg=1&_pgn=1</itemSearchURL> </findItemsByKeywordsResponse>
任何人都可以帮我找到第一层信息,例如 ack 和版本,然后是嵌套在 searchResult->Item 中的信息。
因此,上面我的意思是元素的值......
findItemsByKeywordsResponse->ack findItemsByKeywordsResponse->version
以及嵌套信息,
findItemsByKeywordsResponse->searchResult->item->itemId findItemsByKeywordsResponse->searchResult->item->title
我花了几天时间在网站上寻找答案,但没有找到有效的解决方案。
I am using Linq to XML with the eBay API and am unable to retrieve even basic information from the XML returned. I have tried every combination of from x in y select z
etc but am having no luck.
I am loading the data with
var xml = XDocument.Load ("http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=***MY-KEY-OBSCURED**&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=yamaha&paginationInput.entriesPerPage=1&paginationInput.pageNumber=1");
And I get back the following XML according to the console and LINQPad.
<findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services"> <ack>Success</ack> <version>1.11.0</version> <timestamp>2011-09-04T12:15:10.595Z</timestamp> <searchResult count="1">
<item>
<itemId>220841819907</itemId>
<title>YAMAHA RX-V592 SURROUND SOUND RECEIVER</title>
<globalId>EBAY-US</globalId>
<primaryCategory>
<categoryId>14981</categoryId>
<categoryName>Receivers</categoryName>
</primaryCategory>
<galleryURL>http://thumbs4.ebaystatic.com/pict/2208418199074040_1.jpg</galleryURL>
<viewItemURL>http://www.ebay.com/itm/YAMAHA-RX-V592-SURROUND-SOUND-RECEIVER-/220841819907?pt=Receivers_Tuners</viewItemURL>
<productId type="ReferenceID">46568009</productId>
<paymentMethod>PayPal</paymentMethod>
<autoPay>false</autoPay>
<postalCode>76638</postalCode>
<location>Crawford,TX,USA</location>
<country>US</country>
<shippingInfo>
<shippingServiceCost currencyId="USD">22.0</shippingServiceCost>
<shippingType>Flat</shippingType>
<expeditedShipping>false</expeditedShipping>
<oneDayShippingAvailable>false</oneDayShippingAvailable>
<handlingTime>3</handlingTime>
<shipToLocations>US</shipToLocations>
</shippingInfo>
<sellingStatus>
<currentPrice currencyId="USD">51.0</currentPrice>
<convertedCurrentPrice currencyId="USD">51.0</convertedCurrentPrice>
<bidCount>13</bidCount>
<sellingState>Active</sellingState>
<timeLeft>P0DT0H18M17S</timeLeft>
</sellingStatus>
<listingInfo>
<bestOfferEnabled>false</bestOfferEnabled>
<buyItNowAvailable>false</buyItNowAvailable>
<startTime>2011-08-28T12:33:27.000Z</startTime>
<endTime>2011-09-04T12:33:27.000Z</endTime>
<listingType>Auction</listingType>
<gift>false</gift>
</listingInfo>
<returnsAccepted>false</returnsAccepted>
<condition>
<conditionId>3000</conditionId>
<conditionDisplayName>Used</conditionDisplayName>
</condition>
<isMultiVariationListing>false</isMultiVariationListing>
</item> </searchResult> <paginationOutput>
<pageNumber>1</pageNumber>
<entriesPerPage>1</entriesPerPage>
<totalPages>819204</totalPages>
<totalEntries>819204</totalEntries> </paginationOutput> <itemSearchURL>http://www.ebay.com/sch/i.html?_nkw=yamaha&_ddo=1&_ipg=1&_pgn=1</itemSearchURL> </findItemsByKeywordsResponse>
Can anyone please help me find the 1st tier info such as ack and version and then the information nested within searchResult->Item.
So by the above I mean the values of the elements...
findItemsByKeywordsResponse->ack findItemsByKeywordsResponse->version
and also the nested information
findItemsByKeywordsResponse->searchResult->item->itemId findItemsByKeywordsResponse->searchResult->item->title
I have spent days trawling sites for the answer but have found no working solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尚未显示您尝试过的任何代码,但我强烈怀疑您只是缺少名称空间。代码如下:
You haven't shown any of the code that you've tried, but I strongly suspect you're just missing the namespace. Code like this:
最可能的问题是命名空间。文档中的元素位于命名空间
http://www.ebay.com/marketplace/search/v1/services
中,您必须在查询中反映这一点。因此,通过以下方式检索 ack 的值:
The most likely problem is namespace. The elements in document are in the namespace
http://www.ebay.com/marketplace/search/v1/services
and you have to reflect this in your query. So, with this:Retrieve the value of
ack
by:Ebay 本身提供了一个类库,用于对 ebay 服务器的 clls 进行包装。通过它你可以直接接收强类型对象,而不必自己解析返回的xml。
看看这里,可能会有所帮助:
http://developer.ebay.com/products/finding/
在“工具”下,您可以找到下载内容,包括 .NET 和 Java 的库和示例项目。
Ebay itself offers a class library to have a wrapper around the clls to the ebay server. by it you can directly receive strongly-typed objects and don't have to parse the returned xml yourself.
have a look here, might help:
http://developer.ebay.com/products/finding/
under "Tools" you can find downloads including the library and sample projects for .NET and Java.