Monday, 9 September 2013

No results in LINQ to XML

No results in LINQ to XML

I am completely new to LINQ and want to start learning LINQ to XML. I have
read the documentation and tried to find an answer online, to no avail.
This is the XML I use:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<view name="some_view">
<col name="name">
<width>150</width>
</col>
</view>
<view name="anotherview">
<col name="colname">
<format>D12</format>
</col>
</view>
</parameters>
and I try to fetch the view node of view some_view like this:
XElement root = XElement.Load("params.xml");
var test = from _view in root.Descendants("view") where
_view.Attribute("name").Equals("some_view") select _view;
The root element is there, because a call to root.Descendants("view")
gives me two nodes. But when I run the LINQ as above, I get no result,
where I expect to get the first view node from the XML.

No comments:

Post a Comment