我有一个XMLDocument对象,其InnerXml设置为我从Web服务获取的响应。样本响应如下:
<GetAddressResponse>
<AddressStatus>EXACT MATCH</AddressStatus>
<DefaultAddress>
<FirmName></FirmName>
<Address1></Address1>
<Address2>PO BOX 123</Address2>
<City>DAYTON</City>
<State>OH</State>
<Urbanization></Urbanization>
<Zip5>45475</Zip5>
<Zip4>1952</Zip4>
<CarrierRoute>B017</CarrierRoute>
<CountyName>MONTGOMERY</CountyName>
<DeliveryPoint>52</DeliveryPoint>
</DefaultAddress>
<AddressRecCount>0</AddressRecCount>
</GetAddressResponse>
我需要首先获取并检查AddressStatus的值,然后根据结果获取DefaultAddress下的所有内容。我正在使用.Net3.5,因此如果需要,可以使用Linq。谢谢您提前。
var AddressInfoList = doc.Descendants("GetAddressResponse").Descendants("DefaultAddress").Select(Address => new{ Address = Address.Element("Address2").Value, City = Address.Element("City").Value, State = Address.Element("State").Value, Zip5 = Address.Element("Zip5").Value, Zip4 = Address.Element("Zip4").Value, DPC = Address.Element("DeliveryPoint").Value, }).ToList(); foreach (var AddressInfo in AddressInfoList) {
- NoBullMan