如何在C#for winforms中从该XML响应中检索值
本文关键字:XML 响应 检索 C#for winforms | 更新日期: 2023-09-27 18:00:25
以下是XML响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="somehttp..">
<soap:Body>
<get4GAddressResponse xmlns="http://somelink/">
<get4GCAddressResult>
<located>true</located>
<matchStatus>S</matchStatus>
<errorCode>0</errorCode>
<message>Single Address Match</message>
<addressList>
<anyType xsi:type="Address">
<street>4301 some St</street>
<city>ABC</city>
<state>TX</state>
<zip>78751</zip>
<longitude>-97.700000</longitude>
<latitude>30.308000</latitude>
<coverageTypes>
<anyType xsi:type="NetworkCoverage">
<type>4G</type>
<isCovered>false</isCovered>
</anyType>
</coverageTypes>
</anyType>
</addressList>
</get4GAddressResult>
</get4GAddressResponse>
</soap:Body>
</soap:Envelope>"
我正在尝试从XML元素获取值:"isCovered"我能够从中检索值
<located>true</located>
<matchStatus>S</matchStatus>
<errorCode>0</errorCode>
<message>Single Address Match</message>
但我需要IsCovered的价值。
C#代码:
Location result = new TestWebService.Location();
result = get4GAddress(street, city, state, zip);
if (result != null)
{
if (result.errorCode.Equals("0"))
{
locationresult = new LocationResponse();
locationresult.located = result.located;
locationresult.addressList = result.addressList;
locationresult.matchStatus = result.matchStatus;
locationresult.message = result.message;
}
}
您可以使用SoapFormatter
来反序列化响应流。