Get dom xml item as string and use as array

zookWooview

New Member
I searched the net for hours, but I'm stuck.I used a tutorial for parsing xml, i came to the conclusion it would be best for me to use the DOM xml parser.Mainly cause the content i parse contains only 30 items.the xml looks as folowing:\[code\]<?xml version="1.0" encoding="UTF-8"?><sliderlist><item><urlslide>http://www.google.com</urlslide></item><item><urlslide>http://www.stackoverflow.com</urlslide></item></sliderlist>\[/code\]The DOM parser (most from a tutorial):\[code\]TextView urlslide[]; try { URL url = new URL("http://www.mydomain.com/my.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("item"); /** Assign textview array lenght by arraylist size */ urlslide = new TextView[nodeList.getLength()]; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); urlslide = new TextView(this); Element fstElmnt = (Element) node; NodeList nameList = fstElmnt.getElementsByTagName("urlslide"); Element nameElement = (Element) nameList.item(0); nameList = nameElement.getChildNodes(); urlslide.setText(((Node) nameList.item(0)).getNodeValue()); //layout.addView(urlslide); } } catch (Exception e) { System.out.println("XML Pasing Excpetion = " + e); }\[/code\]And then the part where i need the parsed content fill me array (what now uses the xml inside the values/res folder):\[code\] mTimer=new CountDownTimer(15000, 1000) { String[] myArray = getResources().getStringArray(R.array.testArray); //String[] myArray={"http://www.upc.nl/","http://www.google.com","http://www.flyerwall.nl"}; //<- String should be read from landingpage. int currentIndex=0; public void onTick(long millisUntilFinished) { //if (currentIndex<myArray.length) { //number.setText("seconds remaining: " + millisUntilFinished / 1000); //currentIndex++; //} } public void onFinish() { if (currentIndex<myArray.length) { //number.setText("done!"); mWebView.loadUrl(myArray[currentIndex]); currentIndex++; } else { currentIndex=0;//reset current url to 0 if (currentIndex<myArray.length) //number.setText("done!"); mWebView.loadUrl(myArray[currentIndex]); currentIndex++; mTimer.start(); //activate the loop } mTimer.start();//first time start } };\[/code\]I went to so much sample codes i that i not got a clue anymore,but my guts say it should be so simple to complete.
 
Back
Top