I am working with a method using LINQ to XML to return a string.This is the XML
<data name="lnkViewResultResource1.Text" xml:space="preserve">
<value>View results</value>
</data>
<data name="lnkVoteResource1.Text" xml:space="preserve">
<value>Vote</value>
</data>
<data name="number of results" xml:space="preserve">
<value>You already {0} voted in this poll {1}</value>
</data>
(I want to take the “name” attribute)
This is my method:
Public Shared Function getlabel(ByVal filename As String, ByVal valuetrans As String) As String
Dim label = From l In XElement.Load(filename).Elements("data") Where l.Element("value").Value = valuetrans Select (l.Attribute("name").Value).First
Return label.ToString
End Function
And this is returning this :
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String]
I googled and used following this link FirstOrDefault(), but it didn’t work in my case.
Any ideas?
Thanks in advance,
Alf.
I think your call to ‘First’ is placed wrong, try this: