I am writing a XML parser (LINQ to XML) in C#. Below is an example of the XML structure:
<ASB CATEGORY="TUBE">
<VERSION>700114d2fefesdse34be9cab26a</VERSION>
<ID>106107</ID>
<STRUCT>
<VALUES>9.19 48.491, 9.372 48.56555, 9.4222 48.57472, 9.62361111 48.64833333, 9.74722222 48.680833, 9.74622531 48.665604, 9.744127737 48.65018037, 9.7410232 48.63496203183, 9.7369276269873 48.61984372, 9.73361111 48.60972222, 9.6255556 48.5625, 9.1538889 48.4489, 9.19111 48.491111111</VALUES>
</STRUCT>
</ASB>
Here is the C# code snippet to extract values:
string strAppPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
XDocument xdoc = XDocument.Load(strAppPath + "\\database\\test.xml");
xdoc.Descendants("ASB").Select(p => new {
CATEGORY = p.Attribute("CATEGORY").Value,
VALUES = p.Element("STRUCT").Element("VALUES").Value
}).ToList().ForEach(p => {
textBoxLog.Text += "CATEGORY: " + p.CATEGORY + System.Environment.NewLine + p.VALUES + System.Environment.NewLine + System.Environment.NewLine;
});
Here the values are all printed in the textBoxLog TextBox. When I run the program gets stuck with no return. Also debuggin is no help as I can't read the values! There seems to be no bug in reading XML as if I replace reading values VALUES with ID it works.
For example,
ID = p.Element("ID").Value // Works
VALUES = p.Element("STRUCT").Element("VALUES").Value // Doesn"t work
Since the VALUES node is inside the STRUCT node, I though of writing the above code. Please suggest where is the problem?