如何在VB.NET中读取SOAP XML响应



我想在XML响应中读取CoverDtlList。我想将所有Premium存储在基于CoverDesc的变量中。我尝试使用XmlDocument((,但没有得到我想要的输出。

请帮我解决这个问题。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetQuotResponse xmlns="http://tempuri.org/">
<GetQuotResult>
<POL_SYS_ID>30258992</POL_SYS_ID>
<PROPOSAL_NO>10064/31/23/P/022669</PROPOSAL_NO>
<VehicleIDV>29100</VehicleIDV>
<ERROR_DESC>Proposal created successfully......!</ERROR_DESC>
<ERROR_CODE>0</ERROR_CODE>
<CoverDtlList>
<CoverDtl>
<CoverDesc>BASIC OD COVER</CoverDesc>
<Premium>487.72</Premium>
<Type />
</CoverDtl>
<CoverDtl>
<CoverDesc>OD TOTAL</CoverDesc>
<Premium>487.72</Premium>
<Type />
</CoverDtl>
<CoverDtl>
<CoverDesc>BASIC TP COVER</CoverDesc>
<Premium>752</Premium>
<Type />
</CoverDtl>
<CoverDtl>
<CoverDesc>GR36A-PA FOR OWNER DRIVER</CoverDesc>
<Premium>315</Premium>
<Type>ADD</Type>
</CoverDtl>
<CoverDtl>
<CoverDesc>TP TOTAL</CoverDesc>
<Premium>1067</Premium>
<Type />
</CoverDtl>
</CoverDtlList>
</GetQuotResult>
</GetQuotResponse>
</soap:Body>
</soap:Envelope>

您有一个命名空间问题。尝试xml linq:

Imports System
Imports System.Xml
Imports System.Xml.Linq
Module Program
Const FILENAME As String = "c:temptest.xml"
Sub Main(args As String())
Dim doc As XDocument = XDocument.Load(FILENAME)
Dim xCoverDtls As List(Of XElement) = doc.Descendants().Where(Function(x) x.Name.LocalName = "CoverDtl").ToList()
Dim ns As XNamespace = xCoverDtls.First().GetDefaultNamespace()
Dim coverDtls As List(Of CoverDtl) = xCoverDtls.Select(Function(x) New CoverDtl() With {
.CoverDesc = CType(x.Element(ns + "CoverDesc"), String),
.Premium = CType(x.Element(ns + "Premium"), Decimal),
.Type = CType(x.Element(ns + "Type"), String)
}).ToList()
End Sub
End Module
Public Class CoverDtl
Public CoverDesc As String
Public Premium As Decimal
Public Type As String
End Class

相关内容

  • 没有找到相关文章

最新更新