Extracting Data from XML to List<>

I have this XML file:

<?xml version="1.0" encoding="utf-8" ?>
  <File name="1.mot">
    <Line address="040004" data="0720" />
    <Line address="040037" data="31" />
    <Line address="04004C" data="55AA55AA" />
  <File name="2.mot">
    <Line address="00008242" data="06" />
    <Line address="00008025" data="AFC8" />
    <Line address="00009302" data="476F6C64" />

What I want to do is to extract the information from the XML and convert that to list. Although I kind of don’t know where and how to start. I’ve googled samples, and questions and the code below is what I’ve managed to construct so far. I’m not even sure if this code is appropriate for what I wanted to happen. This list will be used for some kind of lookup in the program. Like in file 1.mot, program would read 1.mot, read the xml file, parse both files, extract the info from the xml file and then do a search function to verify if the info in the xml exists in 1.mot.

XElement xmlReqs = XElement.Load("XMLFile1.xml");
List<Requirement> reqs = new List<Requirements>();
foreach (var xmlReq in xmlReqs.Elements("File"))
    string name = xmlReqs.Attribute("name").Value);
    List<InfoLine> info = new List<InfoLine>();
    foreach (var xmlInfo in xmlReq.Elements("Line"))
      int address = xmlProduct.Attribute("address").Value;
      string data = xmlProduct.Attribute("data").Value;
reqs.Add(new Requirement(address, data));

A friend of mine suggested something about using int array or string array and then using this reqs.Find(val => val[0]==target) but I’m not sure how to do so. I’m not well-versed with linq, but what I’ve gathered, it seems to be quite notable and powerful (?).

Anyway, will the code above work? And how do I call the objects from the list to use for the lookup function of the program?

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.