I'm trying to test the Linq for retrieving some values of elements in the xml file:
Here is the code:
try
{
XElement doc = XElement.Load(@"Z:\test.xml");
string abc, def;
foreach (XElement elm in doc.Descendants().Elements("test"))
{
abc = elm.Element("att").Value;
def = elm.Element("title").Value;
Console.WriteLine(abc);
Console.WriteLine(def);
}
}
catch (XmlException xe)
{
Console.WriteLine(xe);
}
But this doesn't seem to go through the foreach loop. It's not giving me any error. I have debugged it and it reads the xml file just fine. But when it reaches the foreach loop, it just quits. What's the reason.
Part of my XML FILE:
<root xmlns:xsi="w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="test.xsd">
<test att="123" title="XXXX" />
<test att="2324" title="YYYY" />
</root>