Skip to content

Instantly share code, notes, and snippets.

int id[] = result.getAsIntegerArray("//player[middlename]/@id");
int id[] = result.getAsIntegerArray("//player[@rank=null]/@id");
int id[] = result.getAsIntegerArray("//player[@rank]/@id");
String id=result.getAsInteger("//player[//address[country/isocode='CA']]/@id");
int id = result.getAsInteger("//player[lastname='Hewitt']/@id");
int id = result.getAsInteger("//lastname[text()='Hewitt']/../@id");
String first2[] = result.getAsStringArray("//player[position() < 3]/firstname");
String secondLast = result.getAsString("//player[last() - 1]/firstName");
int top2[] = result.getAsIntegerArray("//player[@rank < 3]/@id");
<rankings type="aus" gender="male" date="2011-12-31">
<player id="1036" coretennisid="6752" rank="1" delta="0" singlespoints="485000" doublespoints="675" deductedpoints="0" totalpoints="485675">
<firstname>Bernard</firstname>
<lastname>Tomic</lastname>
<town>SOUTHPORT</town>
<state>QLD</state>
<dob>1992-10-21</dob>
</player>
<player id="2585" coretennisid="1500" rank="2" delta="0" singlespoints="313500" doublespoints="12630" deductedpoints="0" totalpoints="326130">
<firstname>Mathew</firstname>
// get all address_component names anywhere in the document with a type "political"
String array[] = result.getAsStringArray("//address_component[type='political']/long_name");
// get all types anywhere under the second result (dimension is 0-based)
String array[] = result.getAsStringArray("/result[1]//type");