`
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")
精彩评论