【发布时间】:2019-08-16 19:48:31
【问题描述】:
我有以下 SOAP 响应,我想从标记元素中获取值。如何使用 c# 实现这一点?
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<SessionId xmlns="http://schemas.test.com/Practice/">10ac349210ac3492000000001565976562345</SessionId>
<SequenceId xmlns="http://schemas.test.com/Practice/">9852523457481420</SequenceId>
</S:Header>
<S:Body>
<Response xmlns="http://schemas.test.com/Practice/">
<Attributes>
<getResponseSubscription xmlns="http://schemas.test.com/test/UserProfile/Practice/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>5643323</ID>
<name>John Brown Jr</name>
<address>New York</address>
</getResponseSubscription>
</Attributes>
</Response>
</S:Body>
</S:Envelope>
我尝试了以下方法,但它返回 null:
var str = XElement.Parse(xml.Response.XmlResponse.ToString());
var result = str.Element("Address").Value;
NormalRoamingValue.Text = result.ToString();
【问题讨论】: