I have a soap message shown below. I would like to get only 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 am able to get it using 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 dont want to use specific name like "Request" because I have more than soap messages and each have different xml element name. so I need a general function instead of making a specific function for each.
I followed that suggestion(s): Extract SOAP body from a SOAP message
but with this code below, but it doesnt work for me. where am I doing the mistake or how do I extract inside the body part?
Dim myXDocument As XDocument = XDocument.Load(New StringReader(Request))
Dim Xns As XNamespace = XNamespace.Get("soap="http://www.w3.org/2003/05/soap-envelope")
SoapBody = myXDocument.Descendants(Xns + "Body").First().ToString