LinQ to XML

EDN Admin

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

I want to get an node value which matches a specified attribute value.

Below is my code...

XElement xe = XElement.Load(strPath + "\LogsTimeFormats.xml");
Func<XElement, bool> whereClause;
if (strFileName.Contains("*.*"))
{
whereClause = a => a.ToString().IndexOf(strFileName.Substring(0, a.ToString().Length - 4)) > -1;
}
var query = xe.Descendants("File").Where(whereClause).Select(a => a.Value);

The above code does not work, throws exception on the line, whereclause =...."

The strFileName value that is passes is messages*.*

XMl file is

<?xml version="1.0" encoding="utf-8" ?>
<LogFiles>
<File name="messages <![CDATA[MMM d HH:mm:ss]]></File>
<File name="fusionserver*.* <![CDATA[MMM d, yyyy h:mm:ss tt]]></File>
</LogFiles>



Can anyone help me o fix it?

View the full article
 

Similar threads

M
Replies
0
Views
65
Markus Freitag
M
M
Replies
0
Views
100
Markus Freitag
M
P
Replies
0
Views
78
Policy standard local admin account with Active Di
P
Back
Top