C# .Select Method
-
I want to do a .Select for the rest of the fields: EventStatus, EventReason, and EventDateTime like I'm doing for the TrackingEvent and am not sure how to do that. Richard Deeming was helpful in get me started with this but need help with the rest. TrackingEventHistory is the root for XML element I'm trying to output. The rest (EventStatus, EventReason, EventDateTime) are "children" within that root. There can be multiple TrackingEventHistory's so I'm trying to create a loop for the root and it's children. I'm not sure if .Select is the best way.
new XElement("TrackingEventHistory",
prc.History.Cast().Select(item => new XElement("TrackingEventDetail",
new XElement("EventStatus", EventCode.Delivered.ToXml()),
new XElement("EventReason", prc.History),
new XElement("EventDateTime", prc.History)) -
I want to do a .Select for the rest of the fields: EventStatus, EventReason, and EventDateTime like I'm doing for the TrackingEvent and am not sure how to do that. Richard Deeming was helpful in get me started with this but need help with the rest. TrackingEventHistory is the root for XML element I'm trying to output. The rest (EventStatus, EventReason, EventDateTime) are "children" within that root. There can be multiple TrackingEventHistory's so I'm trying to create a loop for the root and it's children. I'm not sure if .Select is the best way.
new XElement("TrackingEventHistory",
prc.History.Cast().Select(item => new XElement("TrackingEventDetail",
new XElement("EventStatus", EventCode.Delivered.ToXml()),
new XElement("EventReason", prc.History),
new XElement("EventDateTime", prc.History)) -
Would something like this work
var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
foreach (XElement element in query)
{
new XElement("EventStatus", EventCode.Delivered.ToXml()),
Response.Write(element.Value);
} -
Would something like this work
var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
foreach (XElement element in query)
{
new XElement("EventStatus", EventCode.Delivered.ToXml()),
Response.Write(element.Value);
}Why not try it and find out?
This space for rent
-
Would something like this work
var query = (from c in doc.Root.Descendants("TrackingEvent") select c).ToList();
foreach (XElement element in query)
{
new XElement("EventStatus", EventCode.Delivered.ToXml()),
Response.Write(element.Value);
}If you haven't downloaded it yet, you really should try out Linqpad[^]. Here's guidance[^] on how to query XLinq in it.
This space for rent