I am trying to use the UPS API to extract the Activity Location using XML. I have written this extract piece.
city = xml.Element("TrackResponse").Element("Package").Element("Activity").Element("ActivityLocation").Element("Address").Element("City")?.Value;
But everytime I run the syntax I get a debug error of:
Additional information: Object reference not set to an instance of an object.
I have checked the documentation and verified that I am using the proper XML data structure hierarchy, but am still not able to extract this element. How should the syntax above be altered in order to extract the city from the UPS API?
And this is a screenshot from the UPS API that shows the XML Hierarchy to follow to extract my desired field.
EDIT
This is how the same field exists twice, (in this instance) I want to extract from Package
parent element, but using FirstOrDefault()
how can I select?
Example 1
<Shipment>
<Shipper>
<Address>
<City>XXXX</City>
</Address>
</Shipper>
</Shipment>
Example 2
<Package>
<Activity>
<ActivityLocation>
<Address>
<City>....</City>
</Address>
</ActivityLocation>
</Activity>
</Package>