Fix bug preventing API keys from being created

PHP cannot determine if a constant is empty with `empty()`—doing so
requires evaluating it against a zero-length string.
Replace generic, non-functional code with XML-parsing code

Per #167.

Note that this is not complete -- this does not work properly yet.