I am a VB6 veteran gradually coming to grips with VB.NET. I have a working app that I am trying to configure using XML files (other than basic app settings).
I want to read elements from a single XML node within my file and create an array of strings. I have searched this site and others and have found many examples that perform very similar operations, but can't quite get the grasp of it (especially if the question / answer is in C#).
I'm no XML expert, but I know how to select the single node and I could write some reasonably neat code that would iterate through the child elements and manually build the array by using redim, and that would work fine. BUT ... i'm trying to learn new techniques by specific example.
So ... it seems that with maybe 2 or 3 fairly compact statements that I should be able to write a LINQ query and use the .ToArray() extension method to populate the array without resorting to a looping construct.
Here is a representation of my XML:
<?xml version="1.0"?>
<targets>
<target name="abc">
<index>0</index>
<randoms>
<string>index</string>
<string>local</string>
<string>news</string>
<string>journal</string>
<string>information</string>
</randoms>
</target>
<target name="xyz">
<index>1</index>
<randoms>
<string>cat</string>
<string>dog</string>
<string>mouse</string>
</randoms>
</target>
</targets>
The elements I want to build the array from are the "string" elements. In my code I would use the target index to select the appropriate node (there would be nodes other than "randoms" but they are not relevant to this example.