First, let me say, that I'm a noob. I'm trying to do an app for Windows Phone 7 and the basics are working pretty well yet. But there is still a big problem with building an article list.
I'm trying to read an XML file with lots of elements and attributes. Part of it is working (Customer Data in the header) but I need a list of all articles in range.
So actually I'm using for the header such commands as:
var queryResult = from item in xml.Descendants("ORDER_HEADER")
select new ErpItem()
{
//Header Data
OrderId = xml.Descendants("ORDER_INFO").Select(c => c.Element("ORDER_ID").Value).First(),
PartyId = xml.Descendants("PARTY").Select(c => c.Element("PARTY_ID").Value).First(),
//....... (more header data to come)
};
Items = queryResult.ToList();
This isn't a problem to me cause with First()
I'm getting the unique customer Data.
But later in my XML File, there are some article related data cause the XML file is in fact a customer order which contains lots of position data in it.
So the First()
method isn't working anymore开发者_开发技巧, cause I need every article item.
So is there a simple way to transform First
to e.g. All
? Every,...
First, if you want to get only data for a specific ORDER_HEADER
, you should call item.Descendants(…)
inside your select
.
Second, if you don't call First()
you will get all the data, so for example, if you called just
item.Descendants("ORDER_INFO").Select(c => c.Element("ORDER_ID").Value)
it would return the value of the first ORDER_ID
for all ORDER_INFO
s.
精彩评论