I really need someone help in trying to get my parser to read and show just one section of xml file, i can get it two read from top to bottom but when i try and use the inner tags in my xml handler that separate each section out it doesn't do it and goes mental and shows one bit of it
This is the code for my Parser
package heavytime
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
//import android.content.Intent;
import android.os.Bundle;
//import android.view.View;
//import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Mainweather extends Seskanoreweatherpart2Activity {
weatherlist sitesList = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
layout.setBackgroundColor(0xFF000080);
TextView value [];
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.seskanore.com/currentoutput.xml");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
XMLhandler XMLhandler = new XMLhandler();
xr.setContentHandler(XMLhandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Get result from XMLhandler SitlesList Object */
sitesList = XMLhandler.sitesList;
/** Assign textview array lenght by arraylist size */
// item = new TextView[sitesList.getName().size()];
value = new TextView[sitesList.getName().size()];
/** Set the result text in textview and add it to layout */
for (int i = 0; i < sitesList.getName().size(); i++) {
value[i] = new TextView(this);
value[i].setText(sitesList.getvalue().get(i)+ " is " +sitesList.getitem().get(i));
layout.addView(value[i]);
}
/** Set the layout view to display */
setContentView(layout);
}
}
This is the code for my XML handler
package heavytime
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class XMLhandler extends DefaultHandler {
Boolean currentElement = false;
Boolean temperature = false;
String currentValue = null;
// int currentVal = 0;
public static weatherlist sitesList = null;
public static weatherlist getSitesList() {
return sitesList;
}
public static void setSitesList(weatherlist sitesList) {
XMLhandler.sitesList = sitesList;
}
@Override
public void startDocument() throws SAXException {
// Some sort of setting up work
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equals("weatherdata"))
{
sitesList = new weatherlist();}
else if (localName.equals("item")){
temperature = true;
String attr = attributes.getValue("name");
sitesList.setValue(attr);}
}
/** Called when tag closing*/
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
/** set value*/
if (localName.equals("temperaturetags")){
localName.equalsIgnoreCase("item");
sitesList.setName(currentValue);
localName.equalsIgnoreCase("value");
sitesList.setitem(currentValue);
}
temperature = false;
}
/** Called to get tag characters*/
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
@Override
public void endDocument() throws SAXException {
// Some sort of finishing up work
}
}
This the Code for my Arraylist for displaying the parsed information
package heavytime
import java.util.ArrayList;
public class weatherlist {
private ArrayList<String> value = new ArrayList<String>();
private ArrayList<String> name = new ArrayList<String>();
private ArrayList<String> item = new ArrayList<String>();
/** In Setter method default it will return arraylist
* change that to add */
public ArrayList<String> getvalue() {
return value;
}
public void setValue(String value) {
this.value.add(value);
}
public ArrayList<String> getName() {
return name;
}
public void setName(String name) {
this.name.add(name);
}
public ArrayList<String> getitem() {
return item;
}
public void setitem(String item) {
this.item.add(item);
}
}
I want it to display just the tags within the temperature tags but ive tried everything and nothing seems to work Can someone please help me
Much appreciated