Created
October 4, 2010 11:15
-
-
Save sbuys/609531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void parseXML(String _doc){ | |
String doc = _doc; | |
xml = new XMLElement(this, doc); | |
//Retrieve runList from plusService | |
//runList is the second child element of plusService, position = 1 | |
XMLElement runList = xml.getChild(1); | |
int runCount = runList.getChildCount(); | |
//println(runCount); //print to the console | |
for(int i=0; i<runCount; i++){ | |
XMLElement run = runList.getChild(i); | |
int elementCount = run.getChildCount(); | |
id = run.getIntAttribute("id"); | |
workoutType = run.getStringAttribute("workoutType"); | |
//println("id:" + "\t" + id); | |
//println("workoutType:" + "\t" + workoutType); | |
//startTime | |
int index = (Integer)runElements.get("startTime"); | |
XMLElement _startTime = run.getChild(index); | |
startTime = _startTime.getContent(); | |
//Distance | |
index = (Integer)runElements.get("distance"); | |
XMLElement _distance = run.getChild(index); | |
distance = _distance.getContent(); | |
//Duration | |
index = (Integer)runElements.get("duration"); | |
XMLElement _duration = run.getChild(index); | |
duration = _duration.getContent(); | |
//Heartrate | |
index = (Integer)runElements.get("heartrate"); | |
//This is a new nikeplus feature, so not all runs have this element | |
if(elementCount>index){ | |
XMLElement _heartrate = run.getChild(index); | |
XMLElement _heartrateAvg = _heartrate.getChild(0); | |
XMLElement _heartrateMin = _heartrate.getChild(1); | |
XMLElement _heartrateMax = _heartrate.getChild(2); | |
String heartrateAvgString = _heartrateAvg.getContent(); | |
String heartrateMinString = _heartrateMin.getContent(); | |
String heartrateMaxString = _heartrateMax.getContent(); | |
heartrateAvg = Integer.parseInt(heartrateAvgString); | |
heartrateMin = Integer.parseInt(heartrateMinString); | |
heartrateMax = Integer.parseInt(heartrateMaxString); | |
} else { | |
heartrateAvg = -1; | |
heartrateMin = -1; | |
heartrateMax = -1; | |
} | |
Run newRun = new Run(id, startTime, distance, duration, heartrateAvg, heartrateMin, heartrateMax); | |
//println(id+","+startTime+","+distance+","+duration+","+heartrateAvg+","+heartrateMin+","+heartrateMax); | |
runs.add(newRun); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment