Friday, 18 July 2014

output xml with a certain attribute



Sorry for being a total noob here, but maybe s/o can point me in the right direction!? I got code off the net and am trying to make it work, but it will not :( the xml is this:




<bla>
<blub>
<this that="one">test one</this>
<this that="two">test two</this>
<this that="three">test three</this>
</blub>
</bla>




And I want to have "this" displayed, where "that" == "two", as you can probably tell ;) but it will only work for the first (one"), not for "two" or "three".


Why does it not continue to the 2nd and 3rd element? Thanks for any advice!



XElement tata = XElement.Load(@"\\somewhere\test.xml");

var tutu = from titi in tata.Elements("blub")
where (string)titi.Element("this").Attribute("that") == "two"
select titi.Element("this");
foreach (XElement soso in tutu)
{
Console.WriteLine(soso.Value);
}

No comments:

Post a Comment