I'm trying to code this in C# so it will output the values for each element in XML.
Sample XML:
<APIVersion>4.0</APIVersion> <PackageTrackingInfo> <TrackingNumber>123456789</TrackingNumber> <PackageDestinationLocation> <City>Seattle</City> <StateProvince>WA</StateProvince> <PostalCode>98107</PostalCode> <CountryCode>US</CountryCode> </PackageDestinationLocation> <PackageDeliveryDate> <ScheduledDeliveryDate>2004-09-15</ScheduledDeliveryDate> <ReScheduledDeliveryDate>2004-09-18</ReScheduledDeliveryDate> </PackageDeliveryDate> <TrackingEventHistory> <TrackingEventDetail> <EventStatus>LK</EventStatus> <EventReason>AQ</EventReason> <EventDateTime>2004-08-22T11:00:00-
08:00</EventDateTime> <EventLocation> <City>SEATTLE</City> <StateProvince>WA</StateProvince> <PostalCode>98107</PostalCode> <CountryCode>US</CountryCode> </EventLocation> <SignedForByName>JOHN GALT</SignedForByName> </TrackingEventDetail> </PackageTrackingInfo>
Here is what I have so far. What would be the best way to handle outputting the XML.
rspxml.Root.Add(
new XElement("API", "4.0"),
new XElement("PackageTrackingInfo",
new XElement("TrackingNumber", prc.ProNumber)
),
new XElement("PackageDestinationLocation",
new XElement("City", prc.Consignee.City),
new XElement("StateProvince", prc.Consignee.State),
new XElement("PostalCode", prc.Consignee.Zipcode),
new XElement("CountryCode", prc.Consignee)
),
new XElement("PackageDeliveryDate",
new XElement("ScheduledDeliveryDate", prc.Consignee),
new XElement("ReScheduledDeliveryDate", prc.Consignee)
));
var els = doc.Root.Elements("AmazonTrackingResponse").FirstOrDefault().Elements("TrackingEventHistory").FirstOrDefault().Elements("TrackingEventDetail");
foreach (XElement row in els) //each row
{
foreach (XElement col in row.Elements("EventStatus"))
{
new XElement("EventStatus", EventCode.Delivered.ToXml());
}
foreach (XElement col in row.Elements("EventReason"))
{
}
foreach (XElement col in row.Elements("EventDateTime"))
{
}
foreach (XElement col in row.Elements("EventLocation"))
{
foreach (XElement subcol in row.Elements("City"))
{
}
foreach (XElement subcol in row.Elements("PostalCode"))
{
}
foreach (XElement subcol in row.Elements("CountryCode"))
{
}
}
foreach (XElement col in row.Elements("EstimatedDeliveryDate"))
{
}
foreach (XElement col in row.Elements("DeliveryAppointmentWindow"))
{
foreach (XElement subcol in row.Elements("Day"))
{
}
foreach (XElement subcol in row.Elements("StartTime"))
{
}
foreach (XElement subcol in row.Elements("EndTime"))
{
}
foreach (XElement subcol in row.Elements("TimeZone"))
{
}
}
}