1

I retrieve xml with several nodes this type

<pickUpPoint puCost="0" code4county="UK*LINCS" puKey="C021P008">
    Louth
</pickUpPoint>

and I've got a string formed from the puKey and the actual value of the node (ie C021P008Louth). What I'm trying to achieve is to search in the whole document for the actual node, but I'm not able for the moment to do something like this

xDataForLINQ.Descendants("pickUpPoint")
            .Where(pp =>(tourPickUp.Contains(pp.Attribute("puKey").Value)) = true)
            .FirstOrDefault();

and then check if the value matches the second part of my string (using contains as well).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
mitomed
  • 2,006
  • 2
  • 29
  • 58
  • 1
    Have a look at this post - http://stackoverflow.com/q/594231/1437962 , also consider this article - http://msdn.microsoft.com/en-us/library/bb675173(v=VS.90).aspx – Yusubov Jun 28 '12 at 11:19
  • Sorry, I tried to put a comment of what I've done so far and answered my own question instead. – mitomed Jun 28 '12 at 11:25
  • This is what I did eventually pickUpPointNode = xDataForLINQ.Descendants("pickUpPoint").FirstOrDefault(pp => (tourPickUp.Contains(pp.Attribute("puKey").Value)) && (tourPickUp.Contains(pp.Value))); Don't know if it's the best thing but it seems to work – mitomed Jun 28 '12 at 11:28
  • No problem, did you tried my references? – Yusubov Jun 28 '12 at 11:30

1 Answers1

0

Perhaps using

xDataForLINQ.Descendants("pickUpPoint")
            .FirstOrDefault(p => (string) p.Attribute("puKey") + p.Value == tourPickUp)

is clearer and more precise.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110