I just have some codes here to clarify my doubts on linq xml parsing. I have the following:
...
{
XDocument xmlDoc = XDocument.Load(@"C:\Build.xml");
var abc = from example in xmlDoc.Descendants("target")
select (string)target.Attribute("if");
...
foreach(string example in abc)
{
...
}
...
}
Can i ask that if it is true that in the line select (string)target.Attribute("if")
i am selecting a string from the xml file from the value of “if” as shown in the xml file below:
<xml>
<target if="thevalue">
</target>
</xml>
then i have this line:
foreach(string example in abc)
Is it true that for every selected string of the “value” of the “if” attribute, i am doing something in the foreach loop.
Yes, this is correct. The variable “example” in your foreach loop will contain the value of the “if” attribute.
try the above code in a console application and you’ll see the values in the console window. Or you could use Debug.WriteLine(example) in a different type of application
This is a better linq query expression however
or change your linq query expression to
EDIT
To help with your issue with the Debugger:
I’ve moved my mouse over abc and I see the debugger pop up the information window as shown in the image below
This first images show the “Results View” has those green arrows. You need to click on those arrows before you can see the result (as the message next to them says)
The second image then shows you the results
