The SOAP document is invalid as it contains an arbitrary semicolons. First, fix the SOAP document.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<env:Header
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsa:Action>http://company.com/MethodResponse</wsa:Action>
<wsa:MessageID>urn:uuid:afc4a308-b476-4af2-8c9c-44a404e10623</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:1f5b8e40-d48f-40bb-8c37-50d82afaa6a5</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-9b4fb7d0-a6d2-4757-9bf8-70ab62d45323">
<wsu:Created>2022-04-30T05:03:12Z</wsu:Created>
<wsu:Expires>2022-04-30T05:08:12Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</env:Header>
<soap:Body>
<MethodResponse
xmlns="http://company.com/">
<MethodResult>
<!-- SOAP Information -->
</MethodResult>
</MethodResponse>
</soap:Body>
</soap:Envelope>
Visual Studio comes with robust XML APIs and utilities for deserializing XML. There's very little reason to write your own XML parser. Copy the XML then in Visual Studio clcik Edit -> Paste Special -> Paste XML as Classes.
// NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.w3.org/2003/05/soap-envelope", IsNullable = false)]
public partial class Envelope
{
private EnvelopeHeader headerField;
private EnvelopeBody bodyField;
private string[] textField;
/// <remarks/>
public EnvelopeHeader Header
{
get
{
return this.headerField;
}
set
{
this.headerField = value;
}
}
/// <remarks/>
public EnvelopeBody Body
{
get
{
return this.bodyField;
}
set
{
this.bodyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")]
public partial class EnvelopeHeader
{
private string actionField;
private string messageIDField;
private string relatesToField;
private string toField;
private Security securityField;
private string[] textField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")]
public string Action
{
get
{
return this.actionField;
}
set
{
this.actionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")]
public string MessageID
{
get
{
return this.messageIDField;
}
set
{
this.messageIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")]
public string RelatesTo
{
get
{
return this.relatesToField;
}
set
{
this.relatesToField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.xmlsoap.org/ws/2004/08/addressing")]
public string To
{
get
{
return this.toField;
}
set
{
this.toField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" +
"")]
public Security Security
{
get
{
return this.securityField;
}
set
{
this.securityField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" +
"")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" +
"", IsNullable = false)]
public partial class Security
{
private Timestamp timestampField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d")]
public Timestamp Timestamp
{
get
{
return this.timestampField;
}
set
{
this.timestampField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
"d", IsNullable = false)]
public partial class Timestamp
{
private System.DateTime createdField;
private System.DateTime expiresField;
private string idField;
/// <remarks/>
public System.DateTime Created
{
get
{
return this.createdField;
}
set
{
this.createdField = value;
}
}
/// <remarks/>
public System.DateTime Expires
{
get
{
return this.expiresField;
}
set
{
this.expiresField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
public string Id
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.w3.org/2003/05/soap-envelope")]
public partial class EnvelopeBody
{
private MethodResponse methodResponseField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://company.com/")]
public MethodResponse MethodResponse
{
get
{
return this.methodResponseField;
}
set
{
this.methodResponseField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://company.com/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://company.com/", IsNullable = false)]
public partial class MethodResponse
{
private object methodResultField;
private string[] textField;
/// <remarks/>
public object MethodResult
{
get
{
return this.methodResultField;
}
set
{
this.methodResultField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
The code is simply.
Envelope envelope;
var mySerializer = new XmlSerializer(typeof(Envelope));
using (var myFileStream = new FileStream("SoapMessage.xml", FileMode.Open))
{
envelope = (Envelope)mySerializer.Deserialize(myFileStream);
}
If you are calling an XML SOAP service then use the Service Reference tool to generate the code.
How to deserialize an object using XmlSerializer
How to: Add, update, or remove a WCF data service reference