C
Cylance
Neues Mitglied
- 0
Hi,
ich versuche ein XML file einzulesen und auszuwerten von tastekid.com das gibt mir ähnliche musiktitel zurück, leider check ich irgendwas nich ganz. Bei Podcasts gehts ohne Probleme aber hier hab ich einen spinner. Bestimmt isses nur ein kleiner fehler kann mir jemand helfen?
so les ich das ein:
und das xml file das ich von tastekid bekomme sieht so aus:
achja das Problem is ich habe so viele items wie es results gibt, das ist ok, aber keinerlei text kein name nichts wird in mein array gespeichert, ich denk da muß ich erstmal in results und da erst nach resource suchen...so in der art, hab haufenweise probiert, aber ich checks nich... keine ahnung...hiiilfe
ich versuche ein XML file einzulesen und auszuwerten von tastekid.com das gibt mir ähnliche musiktitel zurück, leider check ich irgendwas nich ganz. Bei Podcasts gehts ohne Probleme aber hier hab ich einen spinner. Bestimmt isses nur ein kleiner fehler kann mir jemand helfen?
so les ich das ein:
Code:
public static void parse(){
URL url;
try {
url = new URL("http://www.tastekid.com/ask/ws?q=u2&verbose=1");
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 itemLst = doc.getElementsByTagName("resource"); //resource results
Similiararrays.SimName = new String[itemLst.getLength()];
Similiararrays.SimType = new String[itemLst.getLength()];
Similiararrays.SimDescription = new String[itemLst.getLength()];
Similiararrays.SimWikiURL = new String[itemLst.getLength()];
Similiararrays.SimSampleTitle = new String[itemLst.getLength()];
Similiararrays.SimSampleURL = new String[itemLst.getLength()];
for(int i=0; i < itemLst.getLength()-1; 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 media = ielem.getElementsByTagName("enclosure");
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();
String WikiURL = media.item(0).getAttributes().getNamedItem("wUrl").getNodeValue();
Similiararrays.SimWikiURL[i] = WikiURL;
String SampleTitle = media.item(0).getAttributes().getNamedItem("yTitle").getNodeValue();
Similiararrays.SimSampleTitle[i] = SampleTitle;
String sampleurl = media.item(0).getAttributes().getNamedItem("yUrl").getNodeValue();
Similiararrays.SimSampleURL[i] = sampleurl;
}
}
}
} 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();
}
}
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<similar>
<info>
<resource>
<name><![CDATA[U2]]></name>
<type>music</type>
<wTeaser><![CDATA[U2 are an Irish rock band from Dublin. Formed in 1976, the group consists of Bono (vocals and guitar), The Edge (guitar, keyboards and vocals), Adam Clayton (bass guitar), and Larry Mullen, Jr. (drums and percussion). U2's early sound was rooted in post-punk but eventually grew to incorporate influences from many genres of popular music. Throughout the group's musical pursuits, they have maintained a sound built on melodic instrumentals, highlighted by The Edge's textural guitar playing and Bono's expressive vocals. Their lyrics, often embellished with spiritual imagery, focus on personal themes and sociopolitical concerns.U2 formed at Mount Temple Comprehensive School when the members were teenagers with limited musical proficiency. Within four years, they signed with Island Records and released their debut album Boy.]]></wTeaser>
<wUrl><![CDATA[http://en.wikipedia.org/wiki/U2_(music)]]></wUrl>
<yTitle><![CDATA[u2- live - with or without you]]></yTitle>
<yUrl><![CDATA[http://www.youtube.com/v/_Ye8GLPUVsM?version=3&f=videos&c=TasteKid&app=youtube_gdata]]></yUrl>
<yID><![CDATA[_Ye8GLPUVsM]]></yID>
</resource>
</info>
<results>
<resource>
<name><![CDATA[INXS]]></name>
<type>music</type>
<wTeaser><![CDATA[INXS (pronounced "in excess", In-XS) are an Australian rock band, formed as The Farriss Brothers in 1977 in Sydney, New South Wales. Mainstays are Garry Gary Beers on bass guitar, Andrew Farriss on guitar/keyboards, Jon Farriss on drums, Tim Farriss on lead guitar and Kirk Pengilly on guitar/sax. For twenty years, they were fronted by Michael Hutchence on lead vocals, whose "sultry good looks" and magnetic stage presence made him the focal point of the band. Initially known for their New Wave/ska/pop style, they later developed a harder pub rock style, including funk and dance elements.In the early 1980s, INXS first charted in their native Australia with their debut self-titled album, but later garnered moderate success elsewhere with Shabooh Shoobah and a single, "The One Thing".]]></wTeaser>
<wUrl><![CDATA[http://en.wikipedia.org/wiki/Inxs]]></wUrl>
<yTitle><![CDATA[INXS - Never Tear Us Apart]]></yTitle>
<yUrl><![CDATA[http://www.youtube.com/v/_VU9DjQpvMQ?version=3&f=videos&c=TasteKid&app=youtube_gdata]]></yUrl>
<yID><![CDATA[_VU9DjQpvMQ]]></yID>
</resource>
</results>
</similar>
Zuletzt bearbeitet: