C# Can';t从eBay API检索嵌套信息

C# Can';t从eBay API检索嵌套信息,c#,xml,linq,ebay-api,C#,Xml,Linq,Ebay Api,我在eBay API中使用Linq to XML,甚至无法从返回的XML中检索基本信息。我尝试过从x到y再选择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

我在eBay API中使用Linq to XML,甚至无法从返回的XML中检索基本信息。我尝试过从x到y再选择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&amp;_ddo=1&amp;_ipg=1&amp;_pgn=1</itemSearchURL> </findItemsByKeywordsResponse>
Success 1.11.012011-09-04T12:15:10.595Z
220841819907
雅马哈RX-V592环绕声接收器
易趣美国
14981
接受者
http://thumbs4.ebaystatic.com/pict/2208418199074040_1.jpg
http://www.ebay.com/itm/YAMAHA-RX-V592-SURROUND-SOUND-RECEIVER-/220841819907?pt=Receivers_Tuners
46568009
贝宝
假的
76638
克劳福德,德克萨斯州,美国
美国
22
平的
假的
假的
3.
美国
51
51
13
活跃的
P0DT0H18M17S
假的
假的
2011-08-28 12:33:27.000Z
2011-09-04T12:33:27.000Z
拍卖
假的
假的
3000
使用
假的
1.
1.
819204
819204http://www.ebay.com/sch/i.html?_nkw=yamaha&_ddo=1&_ipg=1&_pgn=1
任何人都可以帮我找到第一层信息,如确认和版本,然后是嵌套在searchResult->Item中的信息

所以上面我指的是元素的值

findItemsByKeywordsResponse->ack findItemsByKeywordsResponse->version FindItemsByWordsResponse->ack FindItemsByWordsResponse->version 以及嵌套信息

findItemsByKeywordsResponse->searchResult->item->itemId findItemsByKeywordsResponse->searchResult->item->title FindItemsByWordsResponse->searchResult->item->itemId FindItemsByWordsResponse->searchResult->item->title
我花了好几天的时间在网站上搜寻答案,但没有找到有效的解决方案。

易趣本身提供了一个类库,在连接到易趣服务器的CLL上有一个包装器。通过它,您可以直接接收强类型对象,而不必自己解析返回的xml

看看这里,可能会有帮助:

在“工具”下,您可以找到包括.NET和Java的库和示例项目在内的下载。

您还没有显示任何您尝试过的代码,但我强烈怀疑您只是缺少名称空间。代码如下:

XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services"

XElement ack = doc.Root.Element(ns + "ack");
XElement version = doc.Root.Element(ns + "version");
IEnumerable<string> itemIds = doc.Root.Elements(ns + "searchResult")
                                      .Element(ns + "item")
                                      .Element(ns + "itemId")
                                      .Select(x => (string) x);
xns=”http://www.ebay.com/marketplace/search/v1/services"
XElement ack=doc.Root.Element(ns+“ack”);
XElement版本=doc.Root.Element(ns+“版本”);
IEnumerable itemIds=doc.Root.Elements(ns+“searchResult”)
.要素(ns+“项目”)
.元素(ns+“项目ID”)
.选择(x=>(字符串)x);

最可能的问题是名称空间。文档中的元素位于命名空间
http://www.ebay.com/marketplace/search/v1/services
您必须在查询中反映这一点。因此,有了这个:

XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services";
通过以下方式检索
ack
的值:

 xml.Root.Element(ns + "ack").Value

非常感谢,这就是问题所在。非常感谢,也非常感谢。谢谢,我从这里开始,但这对我来说更像是一个学习曲线,我渴望学习LINQ方法,但非常感谢您的帮助。