开发者

Linq to XML - how to get the value of a attribute

`

XElement config = XElement.Parse (
@"<Response SessionId='426D9AEB1F684849A16D79A6CF48582B' xmlns='http://schemas.tmaresources.com/timssws60.xsd'>
<Status Success='true' Message='Connected' ErrorCode='0' />
</Response>");

XElement response = config.Element("Response");

sessionID = (st开发者_开发百科ring)response.Attribute("SessionId");`

why is response null in this case? how can I get the attribute value SessionId?


Your config variable contains the <Response> element itself.
Calling config.Element("Response") will try to get a <Response> element inside the <Response> element.
Since there isn't any, it returns null.

Change it to

(string)config.Attribute("SessionId")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜