I have a soap message shown below. I would like to get only the request element and its child nodes.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://location.xsd">
<soap:Header xmlns="http://www.server.net/schema/request.xsd">
</soap:Header>
<soap:Body>
<Request ReqRespVersion="large" Version="1" EchoToken="1.0" xmlns="http://mynamespace.com">
.....
</Request>
</soap:Body>
</soap:Envelope>
I can get it with this code.
Dim myXDocument As XDocument = XDocument.Load(New StringReader(Request))
Dim Xns As XNamespace = XNamespace.Get("http://mynamespace.com")
SoapBody = myXDocument.Descendants(Xns + "Request").First().ToString
But I donโt want to use a specific name, for example โRequestโ, because I have more than soap messages, and each has a different xml element name. therefore, I need a generic function instead of creating a specific function for each of them.
I followed these suggestions: Extract SOAP body from SOAP message
but with this code below, but it does not work for me. where am I making a mistake or how to extract a part of the body?
Dim myXDocument As XDocument = XDocument.Load(New StringReader(Request))
Dim Xns As XNamespace = XNamespace.Get("soap="http:
SoapBody = myXDocument.Descendants(Xns + "Body").First().ToString
source
share