0

この奇妙な LINQ エラーが発生します。

タイトル = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String

ここに私が持っているコードがあります:

if (Request.QueryString["Keywords"] != null){
        string keywords = Request.QueryString["Keywords"];
            string myAppID = "HIDDEN";
            var xml = XDocument.Load("http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=" + myAppID + "&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=" + keywords + "&paginationInput.entriesPerPage=5");
            XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services";
            var titles = from item in xml.Root.Descendants(ns + "title")
                              select new{
                                  title = xml.Descendants(ns + "title").Select (x => x.Value),
                              };
        foreach (var item in titles){
                Label1.Text += item;
            } 
        }

XML は次のようになります。

<findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">
<searchReslut count="5">
<item>
    <title></title>
</item>
<item>
    <title></title>
</item>
<item>
    <title></title>
</item>

それを正しく出力しようとしています。

4

3 に答える 3

3

それ以外の

title = xml.Descendants(ns + "title").Select (x => x.Value)

への変更

title = item.Value

ChrisGesslerが示唆するように編集しますが、私の提案で:

if (Request.QueryString["Keywords"] != null)
{
    string keywords = Request.QueryString["Keywords"];
    string myAppID = "HIDDEN";
    var xml = XDocument.Load(/* snip */);
    XNamespace ns = "http://www.ebay.com/marketplace/search/v1/services";
    var titles = xml.Root.Descendants(ns + "title").Select(x => x.Value);
    Label1.Text = String.Join(null, titles);
}
于 2012-06-27T15:43:01.517 に答える
1

私はこれを考えています:

var titles = from item in xml.Root.Descendants(ns + "title")                               
             select new{                                   
                title = xml.Descendants(ns + "title").Select (x => x.Value)}; 

次のようにする必要があります。

var titles = from item in xml.Root.Descendants(ns + "title")                               
             select item.Value);
于 2012-06-27T15:55:58.370 に答える