Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
First Linq To XML query - having problems
Message
De
14/04/2009 17:56:26
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
14/04/2009 17:44:42
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Divers
Thread ID:
01394795
Message ID:
01394866
Vues:
53
>>>>Here's my query:
>>>>
>>>>            var query = from m in _AdministrativeTabMappings.Elements("Mappings").Elements("Mapping")
>>>>                        where m.Attribute("Page").Value == page
>>>>                        select m;
>>>>
>>>>
>>>>Query always returns a NullReferenceException. This works without the where clause. Page is a variable which I confirmed equals "bonds/administrator/AdministratorHome.aspx".
>>>
>>>Page isn't an attribute, it's an element. An attribute would be something like:
>>>
>>>
>>><Page name="MyNameAttribute"Value</Page
>>>
>>>
>>>I can't test this, but maybe something like this would work?
>>>
>>>
>>>var query = from m in _AdministrativeTabMappings.Elements("Mappings").Decendants("Page")
>>>                        where m.Value == page
>>>                        select m;
>>>
>>>
>>
>>That returns one result like I would expect, but this code fails when I'm trying to get the value I want:
>>
>>            foreach (var item in query)
>>            {
>>                result = item.Element("Tab").Value;
>>            }
>>
>
>
>In comprehension syntax:
>
>
string result = ( from m in _AdministrativeTabMappings.Elements("Mapping")
> where m.Element("Page").Value == page
> select m).Single().Element("Tab").Value;
>
>In method syntax:
>
>
>string result = 
>   _AdministrativeTabMappings.Elements("Mapping")
>   .Where( m => m.Element("Page").Value == page )
>   .Single()
>   .Element("Tab").Value;
>
Cetin

thanks!
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform