Ich habs endlich: so gehts:
Delphi-Quellcode:
public static void parse()
{
URL url;
try {
url = new URL("http://www.tastekid.com/ask/ws?q=" + MRUtils.mSimiliarTitle + "&verbose");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc;
doc = db.parse(url.openStream());
doc.getDocumentElement().normalize();
NodeList XResultLst = doc.getElementsByTagName("similar");
Node XResultitem = XResultLst.item(0);
NodeList ResultLst = ((Element) XResultitem).getElementsByTagName("results");
Node Resultitem = ResultLst.item(0);
NodeList itemLst = ((Element) Resultitem).getElementsByTagName("resource");
Integer ResultsCount = itemLst.getLength();
Similiararrays.SimName = new String[ResultsCount];
Similiararrays.SimType = new String[ResultsCount];
Similiararrays.SimDescription = new String[ResultsCount];
Similiararrays.SimWikiURL = new String[ResultsCount];
Similiararrays.SimSampleTitle = new String[ResultsCount];
Similiararrays.SimSampleURL = new String[ResultsCount];
for(int i=0; i < ResultsCount; i++){
Node item = itemLst.item(i);
if(item.getNodeType() == Node.ELEMENT_NODE){
Element ielem = (Element)item;
NodeList SimName = ielem.getElementsByTagName("name");
NodeList SimType = ielem.getElementsByTagName("type");
NodeList description = ielem.getElementsByTagName("wTeaser");
NodeList SimWikiURL = ielem.getElementsByTagName("wUrl");
NodeList SimSampleTitle = ielem.getElementsByTagName("yTitle");
NodeList SimSampleURL = ielem.getElementsByTagName("yUrl");
Similiararrays.SimName[i] = SimName.item(0).getChildNodes().item(0).getNodeValue();
Similiararrays.SimType[i] = SimType.item(0).getChildNodes().item(0).getNodeValue();
Similiararrays.SimDescription[i] = description.item(0).getChildNodes().item(0).getNodeValue();
Similiararrays.SimWikiURL[i] = SimWikiURL.item(0).getChildNodes().item(0).getNodeValue();
Similiararrays.SimSampleTitle[i] =SimSampleTitle.item(0).getChildNodes().item(0).getNodeValue();
Similiararrays.SimSampleURL[i] = SimSampleURL.item(0).getChildNodes().item(0).getNodeValue();
}
}
}
} catch (MalformedURLException e)
{
e.printStackTrace();
} catch (DOMException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} catch (ParserConfigurationException e)
{
e.printStackTrace();
} catch (SAXException e)
{
e.printStackTrace();
}
}