Grabbing XML File Data from a Website

Just wondering what would be the best way to grab the following data and parse it.

Here’s an example of some the data I want to pull.

<?xml version="1.0" encoding="UTF-8" ?> 
<eveapi version="2">
    <currentTime>2010-11-19 19:23:44</currentTime> 
    <result>
        <rowset name="characters" key="characterID" columns="name,characterID,corporationName,corporationID">
            <row name="jennyhills" characterID="90052591" corporationName="Imperial Academy" corporationID="1000166" /> 
       </rowset>
    </result>
    <cachedUntil>2010-11-19 20:20:44</cachedUntil> 
</eveapi>

I’ve seen some examples on how to parse XML data but they are all based on if statements and that’s a lot of hard coding is there a more generic way to do this?

Answer

The “parsing”, taking the term literally, is easy. Parsing is the process of taking a text string (in your case, from an http response) and turning it into a data structure such as an XML document tree. That process is handled for you by an XML parser, and you typically don’t need to worry about it.

The part you’re facing is how to query data from the parsed XML document, right? The easiest way to depends greatly on what you need to do with the data. But XPath is a good way to select data without a lot of verbose if statements and get-child function calls.

See also this question on using XPath in Android.