# WolframAlpha XML parsing error

I am using the WolframAlpha command to automated solution sets of homework exercises. Here is an sample usage, although this can happen with many different examples:

WolframAlpha["limit (1 + k)^10/(10*k^10) as k -> Infinity", {{"Limit", 2}, "Content"}, PodStates -> {"Limit__Step-by-step solution"}]


Every so often, I receive the error message:

XMLParserXMLGetString::prserr: The main XML document cannot be empty at Line: 6 Character: 1.


When I reissue the command, it returns fine. That would seem to indicate that it is a timeout issue. OTOH, using the TimeConstraint option returns a different message.

Therefore, I would like to know what causes this, in order to build a workaround. Alternatively, to know (programmatically) that it happened (in some error value), in order to reissue the command.

TYVM.

• Can you include the command you are running? The fact that TimeConstrained returns a different error does not surprise me, since the failure mode becomes different (your code is aborted locally rather than failing). Jun 22 at 12:17
• @MarcoB, thank you for your reply. I have included a sample invocation, although the error message can either happen or not, with many different types of invocations. Jun 22 at 14:50
• 1) This is likely an intermittent connection problem. 2) how to avoid it -> That will depend on what is actually being returned upon error. WolframAlpha returns a RawBoxes object when the call works. I could not reproduce the error, so I don't know what would be returned in that case (maybe $Failed?), but you could check for an unexpected Head in the return value. Maybe wrap wa = WolframAlpha[...] in While and re-evaluate it until Head[wa] returns RawBoxes? Jun 22 at 15:14 • And an aside: I know that this is not your point, but in the particular example you propose, I personally would find the results of Apart[(1 + k)^10/(10*k^10)] much clearer in illustrating why the limit is$1/10\$ than the explanation given by W|A. Jun 22 at 15:18
• @MarcoB, excellent suggestion. I ran this 50 times -- no problems. I ran it another 50 times and "fortunately" the problem reared its ugly Head and it equaled: Missing. Thanx again. Jun 22 at 21:30

## 1 Answer

Thank you again to @MarcoB for guiding me.

Due to all of the possible results from WolframAlpha, it would be difficult to tag what is a valid result, and what suffered from what is apparently a connection problem. Specifically, Missing could be either.

Therefore, the way to go to is to check the system whether an error occurred, either a specific one (like parse error mentioned in the question), or any error. This can easily be accomplished with Check or MessageList.