I have the following XML response:
<S:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns0:RespOpReportGen
xmlns:ns7="http://my.service.url/Schemas/folder1"
xmlns:ns4="http://my.service.url/framework/folder2"
xmlns:ns13="http://my.service.url/framework/folder3"
xmlns:ns0="http://my.service.url/framework/folder4">
<ns0:contextResponse>
<ns4:trnResult>
<ns13:trnStatus/>
<ns13:OKNOResponse>B</ns13:OKNOResponse>
<ns13:ApprovalNr>0</ns13:ApprovalNr>
<ns13:trnID>213454567</ns13:trnID>
<ns13:trnDate>2019-03-13T13:02:10.76</ns13:trnDate>
</ns4:trnResult>
</ns0:contextResponse>
<ns0:FileResponse>
<ns7:contentFile>JVBERi0</ns7:contentFile>
<ns7:mimeType>application/pdf</ns7:mimeType>
</ns0:FileResponse>
</ns0:RespOpReportGen>
</S:Body>
</S:Envelope>
I use the following code in order to obtain the value in tag ns7:contentFile
Dim soapResultXml As XmlDocument = New XmlDocument()
soapResultXml.LoadXml(soapResult)
Dim resultado As XmlNodeList = soapResultXml.GetElementsByTagName("contentFile")
... but i got no results.
Is there a way to obtain the tags by part of the name? or ... how can i obtain "ns7:" value to concatenate it with "contentFile" ?
Thanks in advance, and best regards.
EDIT
Dim soapResultXml As XmlDocument = New XmlDocument() soapResultXml.LoadXml(soapResult) Dim resultado As XmlNodeList = soapResultXml.SelectNodes("//*[contains(name(),'contentFile')]")
It works too.
You need to add and configure XmlNamespaceManager
. Something like this.
Dim soapResultXml As XmlDocument = New XmlDocument()
soapResultXml.LoadXml(soapResult)
Dim xnm as New XmlNamespaceManager(soapResultXml.NameTable)
xnm.AddNamespace("ns7", "http://my.service.url/folder1")
''//add more namespaces
''// xnm.AddNamespace("ns8", "http://my.service.url/folder2")
''//prefix doesn't matter. URI matters.
Dim resultado As XmlNodeList = soapResultXml.SelectNodes("contentFile", xnm)