1

`

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 = (string)response.Attribute("SessionId");`

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

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.