Trying to parse out this xml file to get a list of Elements but I’m having difficulties in doing so.
Here’s my Xml file:
<STORES>
<Stores1>
<TEST>
<ClientID>200</ClientID>
<FormTypeID>101</FormTypeID>
</TEST>
<PROD>
<ClientID>200</ClientID>
<FormTypeID>102</FormTypeID>
</PROD>
</Stores1>
<Stores2>
<TEST>
<ClientID>201</ClientID>
<FormTypeID>717</FormTypeID>
</TEST>
<PROD>
<ClientID>201</ClientID>
<FormTypeID>719</FormTypeID>
</PROD>
</Stores2>
</STORES>
What I am trying to accomplish is pull back all of child elements depending on what I feed the querys XNames parameter for the Elements method call. Like so
var elements = (from x in xDoc.Elements("Stores1")
where x.Name.LocalName == "TEST"
select x).ToList();
So the list would contain all of TEST Elements for Stores1 like this:
<ClientID>200</ClientID>
<FormTypeID>101</FormTypeID>
I get nothing returned at the moment. What am I doing wrong?
xDoc.Elements("Stores1")returns all of the direct child elements of the document namedStores1.You want
xDoc.Element("STORES").Element("Stores1").Elements("TEST").Elements(); you don’t need any LINQ