Hey Everyone, I have spent quite a few hours reading and learning about linq to xml, but i have hit a roadblock here. Here is an example of my xml file:
<project>
<project_number>20071234</project_number>
<project_name>ProjectA</project_name>
<project_unc>\\fileserver1\projects\</project_unc>
<contract>
<full_name>Contract 00 Project1</full_name>
<directory_name>00_Project1</directory_name>
</contract>
<contract>
<full_name>Contract 01 Project2</full_name>
<directory_name>01_Project2</directory_name>
</contract>
</project>
<project>
<project_number>20081234</project_number>
<project_name>ProjectB</project_name>
<project_unc>\\fileserver2\projects\</project_unc>
<contract>
<full_name>Contract 00 Project3</full_name>
<directory_name>00_project3</directory_name>
</contract>
<contract>
<full_name>Contract 01 Project4</full_name>
<directory_name>01_project4</directory_name>
</contract>
</project>
In my program someone is going to pick a project_number from a dropdown list. When they do this it will trigger a query on the XML file that will grab that project_number, and look for all contracts.
XDocument XDoc = null;
XDoc = XDocument.Load("projects.xml");
List<ProjectContract> pc = new List<ProjectContract>(); //created in class
var query = from xml in XDoc.Descendants("project") where (string)xml.Element("project_number") == dropDown1.SelectedItem
select new ProjectContract
{
fullname = (string)xml.Element("contract").Element("full_name"),
dirname = (string)xml.Element("contract").Element("directory_name")
};
pc = query.ToList();
I'm obviously doing something wrong here, i just can't see what. This code only returns the first contract item from either project, but not both. Any help would be greatly appreciated!!