Monday, April 30, 2012

Select statement for xdoc query

I am trying to add a sub category to Messages in my xml statement Is there a way I can do this GroupMessages -> Message -> GroupMessage :

        var groups = xDoc.Descendants("Group")
.Select(n => new
GroupName = n.Element("GroupName").Value,
GroupHeader = n.Element("GroupHeader").Value,
TimeCreated = DateTime.Parse(n.Element("TimeAdded").Value),
Tags = n.Element("Tags").Value,
Messages = n.Element("GroupMessages").Value
//line above

In my method GroupMessages contains both MessageID and GroupMessage and it is listing both in my datagrid within the one container. So I tryed this but it lists nothing:

 Messages = n.Descendants("GroupMessages").Select(nd => nd.Element("GroupMessage").Value)

My xml looks like this:


I have also tryed:

Messages = n.Descendants("GroupMessages").Select(nd => nd.Descendants("Message").Select(nde => nde.Element("GroupMessage").Value))

To no avail?

No comments:

Post a Comment