Question

I'm using vb.net and I have a WebService that sends me a SOAP envelope as a result.

<?xml version="1.0" encoding="utf-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <tfd:Answer DateAnswer="2014-05-02T17:19:38" Certificate="30001000000100000801" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </soapenv:Body>
</soapenv:Envelope>

I'm already able to obtain individual values from inside de XML like DateAnswer or Certificate but now I need to receive the whole section with the "Answer" tag for later storage. In other words this:

<tfd:Answer DateAnswer="2014-05-02T17:19:38" Certificate="30001000000100000801" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

Is there a simple way to obtain this whole section in a string? I've looked it up but I sense I'm not using the correct key words for the search.

Was it helpful?

Solution

Here is the code I used to solve my problem.

Dim Xns As XNamespace = XNamespace.Get("http://schemas.xmlsoap.org/soap/envelope/")
mySection = myXMLDocument.Descendants(Xns + "Body").First().FirstNode.ToString()

"mySection" contains the string I need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top