XML using LINQ with VB.NET



Below is a copy of my xml. Basically what I have is different crops(rice, soybeans, corn, etc) within each crop I have a field node and within that node there are several nodes describing the field. I also have an expense node that contains several expenses within that field node. Expenses can vary within each field which is why i have a node that can contain all of them. What I want to do is find an easy way to query this stuff. Lets say i want to get all the info for one particular field. Well in my app if they select a certain crop then i need to list all the fields in a combobox. Is my structure correct or is there another way to do this. What if i want to add all the expenses up for all the fields in a particular crop and lets say there are 20-30 fields. How can i do this? I know how to select certain things where value = 'something' but the main thing i need to do select all fields for a particular crop and add the expeneses. Or if i select a crop and field in my app then i need to be able to pull all the data from the field node. Any help would be great!



<Data>
<Crop>
<Name>Corn</Name>
<Field>
<Name>Field1</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
<Field>
<Name>Field2</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
</Crop>
<Crop>
<Name>Soybeans</Name>
<Field>
<Name>Field2</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
<Field>
<Name>Field1</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
</Crop>
<Crop>
<Name>Rice</Name>
<Field>
<Name>Field3</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
<Field>
<Name>Field4</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
<Field>
<Name>Field5</Name>
<Acres></Acres>
<Bushels></Bushels>
<Expenses>
<expense1></expense1>
<expense2></expense2>
etc....
</Expenses>
</Field>
</Crop>

No comments:

Post a Comment