using System.Xml.Serialization;
using System.Collections.Generic;
public static void Main()
string resultContent = @"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<getRTLCitiesResponse xmlns=""http://track.smsaexpress.com/secom/"">
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns="""" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" id=""NewDataSet"">
<xs:element name=""NewDataSet"" msdata:IsDataSet=""true"" msdata:UseCurrentLocale=""true"">
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""RetailCities"">
<xs:element name=""routCode"" type=""xs:string"" minOccurs=""0"" />
<xs:element name=""rCity"" type=""xs:string"" minOccurs=""0"" />
<diffgr:diffgram xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
<RetailCities diffgr:id=""RetailCities1"" msdata:rowOrder=""0"">
<RetailCities diffgr:id=""RetailCities2"" msdata:rowOrder=""1"">
<RetailCities diffgr:id=""RetailCities3"" msdata:rowOrder=""2"">
var envelope = DeserializeXml<SoapEnvelope>(resultContent);
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(
envelope.Body.GetRTLCitiesResponse.GetRTLCitiesResult.Diffgram,
new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
private static T DeserializeXml<T>(string xml)
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (StringReader reader = new StringReader(xml))
return (T)serializer.Deserialize(reader)!;
[XmlRoot(ElementName = "RetailCities")]
[XmlElement(ElementName = "routCode")]
public string RoutCode { get; set; }
[XmlElement(ElementName = "rCity")]
public string RCity { get; set; }
[XmlRoot(ElementName = "NewDataSet")]
[XmlElement(ElementName = "RetailCities")]
public List<RetailCity> RetailCities { get; set; } = new List<RetailCity>();
[XmlRoot(ElementName = "diffgram", Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1")]
[XmlElement(ElementName = "NewDataSet", Namespace = "")]
public NewDataSet NewDataSet { get; set; }
[XmlRoot(ElementName = "getRTLCitiesResult", Namespace = "http://track.smsaexpress.com/secom/")]
public class GetRTLCitiesResult
[XmlElement(ElementName = "diffgram", Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1")]
public Diffgram Diffgram { get; set; }
[XmlRoot(ElementName = "getRTLCitiesResponse", Namespace = "http://track.smsaexpress.com/secom/")]
public class GetRTLCitiesResponse
[XmlElement(ElementName = "getRTLCitiesResult")]
public GetRTLCitiesResult GetRTLCitiesResult { get; set; }
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[XmlElement(ElementName = "getRTLCitiesResponse", Namespace = "http://track.smsaexpress.com/secom/")]
public GetRTLCitiesResponse GetRTLCitiesResponse { get; set; }
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class SoapEnvelope
[XmlElement(ElementName = "Body")]
public SoapBody Body { get; set; }
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces Xmlns { get; set; } = new XmlSerializerNamespaces();
Xmlns.Add("soap", "http://schemas.xmlsoap.org/soap/envelope/");
Xmlns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
Xmlns.Add("xsd", "http://www.w3.org/2001/XMLSchema");