XML Parsing - Linq

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,

I am stuck up in parsing an XML using Linq,

My XMl file is as below... I want to get all the <File> node values which matches a specifi <File> node in the <Files> node

For eg: I want to get "fusionserver.log, fmvifmonitor.log, event.log" as a result, when the user passes messages as the input

<?xml version="1.0" encoding="utf-8" ?>
<LogFiles>
<Files>
<File>messages</File>
<File>fusionserver.log</File>
<File>fmvifmonitor.log</File>
<File>event.log</File>
<File>ajscanner.log</File>
</Files>
<Files>
<File>cifsservicemonitor.log</File>
<File>quotamonitor.err</File>
<File>Iad.log</File>
<File>ibrcfrworkerd.log</File>
</Files>
</LogFiles>

I tried with the below code, it throws exception Expression can not contain lambda expressions

f.Root.Descendants("Files").Where(x => x.Element("File").Value = "messages").Select(x => x.Element("File").Value);

Please help me on this!

View the full article
 
Back
Top