0
Dim page As XElement = _
<response>
    <results>
        <result>
            <status>OK</status>
            <number>phonenumberhere</number>
            <wless>y</wless>
            <carrier_name>ATT Mobility</carrier_name>
            <sms_address>[email protected]</sms_address>
            <mms_address>[email protected]</mms_address>
        </result>
    </results>
</response>

Me.addr = page.Element("sms_address").Value

It crashes on Me.addr = page.Element("sms_address").Value I need to store the sms_address as a string.

Can anyone help?

1 Answer 1

1

Try

Dim page As XElement = <response><results><result><status>OK</status><number>phonenumberhere</number><wless>y</wless><carrier_name>ATT Mobility</carrier_name><sms_address>[email protected]</sms_address><mms_address>[email protected]</mms_address></result></results></response>
Me.addr = page.Element("results") _
              .Element("result") _
              .Element("sms_address").Value

The element you were looking for is not at the top, so page.Element("sms_address") won't find it.

Alternatively, since you're lucky enough to be using VB.NET, you can use

page...<sms_address>.Value

or

page.<results>.<result>.<sms_address>.Value
Sign up to request clarification or add additional context in comments.

4 Comments

I get an error Leading '.' or '!' can only appear inside a 'With' statement.
Add line continuation characters to the end of each broken line. Also the first .Element("response") is wrong. Remove that.
@Enigmativity: fixed, I think. My Visual Studio is broken right now, so I can't test it. And I thought they had gotten rid of the need for line continuations. Would it have worked if I broke the line after the .?
@JohnSaunders - They got rid of most of the cases where you needed a line continuation. Now it's real annoying, not just annoying. And yes, if you did the . at the end of the line you wouldn't need the line continuations, but that just makes it hard to read.

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.