public USPSShipmentResponse ParseShipmentResponse(XmlDocument shipmentResponse) { USPSShipmentResponse shipmentinfo = new USPSShipmentResponse(); shipmentinfo.IsDomestic = true; XmlElement elem = shipmentResponse.DocumentElement; if (elem != null) { if (elem.Name.ToLower().Trim() != "error") { if (elem.SelectSingleNode("DeliveryConfirmationNumber") != null) shipmentinfo.DeliveryConfirmationNumber = elem.SelectSingleNode("DeliveryConfirmationNumber").InnerXml; if (elem.SelectSingleNode("Postnet") != null) shipmentinfo.Postnet = elem.SelectSingleNode("Postnet").InnerXml; if (elem.SelectSingleNode("ToName") != null) shipmentinfo.ToName = elem.SelectSingleNode("ToName").InnerXml; if (elem.SelectSingleNode("ToFirm") != null) shipmentinfo.ToFirm = elem.SelectSingleNode("ToFirm").InnerXml; if (elem.SelectSingleNode("ToAddress1") != null) shipmentinfo.ToAddress1 = elem.SelectSingleNode("ToAddress1").InnerXml; if (elem.SelectSingleNode("ToAddress2") != null) shipmentinfo.ToAddress2 = elem.SelectSingleNode("ToAddress2").InnerXml; if (elem.SelectSingleNode("ToState") != null) shipmentinfo.ToState = elem.SelectSingleNode("ToState").InnerXml; if (elem.SelectSingleNode("ToZip4") != null) shipmentinfo.ToZip4 = elem.SelectSingleNode("ToZip4").InnerXml; if (elem.SelectSingleNode("DeliveryConfirmationLabel") != null) { var encoding = new ASCIIEncoding(); shipmentinfo.LabelString = elem.SelectSingleNode("DeliveryConfirmationLabel").InnerXml; shipmentinfo.Label = Convert.FromBase64String( elem.SelectSingleNode("DeliveryConfirmationLabel").InnerXml.ToString().Trim()); } shipmentinfo.TempLabelPath = SaveLabel(shipmentinfo.DeliveryConfirmationNumber, shipmentinfo.Label); } else { string error = elem.InnerXml; shipmentinfo.IsFailed = true; shipmentinfo.Error = error; } } return shipmentinfo; }
public USPSShipmentResponse ParseShipmentResponseIntl(XmlDocument shipmentResponse) { USPSShipmentResponse shipmentinfo = new USPSShipmentResponse(); shipmentinfo.IsDomestic = false; XmlElement elem = shipmentResponse.DocumentElement; if (elem != null) { if (elem.Name.ToLower().Trim() != "error") { if (elem.SelectSingleNode("Postage") != null) shipmentinfo.IntlResponse.Postage = decimal.Parse(elem.SelectSingleNode("Postage").InnerXml); //if (elem.SelectSingleNode("TotalValue") != null) // shipmentinfo.Postnet = elem.SelectSingleNode("TotalValue").InnerXml; if (elem.SelectSingleNode("BarcodeNumber") != null) shipmentinfo.IntlResponse.BarcodeNumber = elem.SelectSingleNode("BarcodeNumber").InnerXml; if (elem.SelectSingleNode("SDRValue") != null) shipmentinfo.IntlResponse.SDRValue = elem.SelectSingleNode("SDRValue").InnerXml; if (elem.SelectSingleNode("Regulations") != null) shipmentinfo.IntlResponse.Regulation = elem.SelectSingleNode("Regulations").InnerXml; if (elem.SelectSingleNode("Prohibitions") != null) shipmentinfo.IntlResponse.Prohibitions = elem.SelectSingleNode("Prohibitions").InnerXml; if (elem.SelectSingleNode("Restrictions") != null) shipmentinfo.IntlResponse.Restrictions = elem.SelectSingleNode("Restrictions").InnerXml; if (elem.SelectSingleNode("Observations") != null) shipmentinfo.IntlResponse.Observations = elem.SelectSingleNode("Observations").InnerXml; if (elem.SelectSingleNode("AdditionalRestrictions") != null) shipmentinfo.IntlResponse.AdditionalRestrictions = elem.SelectSingleNode("AdditionalRestrictions").InnerXml; if (elem.SelectSingleNode("LabelImage") != null) { var encoding = new ASCIIEncoding(); shipmentinfo.LabelString = elem.SelectSingleNode("LabelImage").InnerXml; shipmentinfo.IntlResponse.Label = Convert.FromBase64String(elem.SelectSingleNode("LabelImage").InnerXml.ToString().Trim()); } //::TODO not checked yet InterNational Mode shipmentinfo.TempLabelPath = SaveLabel(shipmentinfo.DeliveryConfirmationNumber, shipmentinfo.IntlResponse.Label); } else { string error = elem.InnerXml; shipmentinfo.IsFailed = true; shipmentinfo.Error = error; } } return shipmentinfo; }