SAX Parser not parsing photograph tag in my xml?

Nurta

New Member
I have been using SAX parser to parse an xml file which has been working fine so far but for some reason won't parse the image url in the photograph tag (I want to parse the url as a string) . Was hoping someone would know the reason? any help would be appreciated.This is the XML:\[code\]<candidate> <name>Scott Web</name> <office>Vice President (Academic Affairs)</office> <photograph> http://www.inf.ed.ac.uk/teaching/courses/selp/elections/ScottWeb.jpg </photograph> <promises> <promise>University 2.0!</promise> <promise>Poducation!</promise> <promise>Lectures as tweets!</promise> <promise>Personal Tutors on Skype</promise> <promise>Grades on IM!</promise> <promise>Feedback HD</promise> <promise>360-degree learning portal</promise> </promises> <statement>I have made it my mission to ensure that this university gets an upgrade and defrag. Lectures and tutorials in the 21st century need to be on-line and interactive. Vote for the future: vote for Scott Web!</statement></candidate>\[/code\]and this is the code for my SAX parser:\[code\]public class XMLHandler extends DefaultHandler {String elementValuehttp://stackoverflow.com/questions/13736535/= "";Boolean elementOn = false;Boolean inPromises = false;public static XMLGettersSetters data = http://stackoverflow.com/questions/13736535/null;public static ArrayList<XMLGettersSetters> candList = new ArrayList<XMLGettersSetters>();public static ArrayList<XMLGettersSetters> getCandList() { return candList;}@Overridepublic void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { elementOn = true; if (localName.equals("candidate")) { data = http://stackoverflow.com/questions/13736535/new XMLGettersSetters(); } else if (localName.equals("promises")) { inPromises = true; } }/** * This will be called when the tags of the XML end. **/@Overridepublic void endElement(String uri, String localName, String qName) throws SAXException { elementOn = false; /** * Sets the values after retrieving the values from the XML tags * */ if (localName.equalsIgnoreCase("name")) data.setName(elementValue); else if (localName.equalsIgnoreCase("office")) data.setOffice(elementValue); else if (localName.equalsIgnoreCase("photograph")) data.setPhotograph(elementValue); else if (localName.equalsIgnoreCase("promise")) { if(inPromises){ data.setPromise(elementValue); } } else if (localName.equalsIgnoreCase("statement")) data.setStatement(elementValue); else if(localName.equalsIgnoreCase("candidate")) candList.add(data);}/** * This is called to get the tags value **/@Overridepublic void characters(char[] ch, int start, int length) throws SAXException { if (elementOn) { elementValue = http://stackoverflow.com/questions/13736535/new String(ch, start, length); elementOn = false; }}\[/code\]and more:\[code\]public class XMLGettersSetters { private String name = null; private String office = null; private String photograph = null; private ArrayList<String> promise = new ArrayList<String>(); private String statement = null; private String promises = null;public XMLGettersSetters() {}public XMLGettersSetters(String name, String office, String photograph, String promises, String statement) { this.name = name; this.office = office; this.photograph = photograph; this.promises = promises; this.statement = statement;}public String getName() { return name;}public void setName(String name) { this.name=name; Log.i("This is the name:", name);}public String getOffice() { return office;}public void setOffice(String office) { this.office=office; Log.i("This is the office:", office);}public String getPhotograph() { return photograph;}public void setPhotograph(String photograph) { this.photograph=photograph.trim(); Log.i("This is the photo url:", photograph);}public ArrayList<String> getPromise() { return promise;}public void setPromise(String promise) { this.promise.add(promise); Log.i("This is the promise:", promise);}public String getStatement() { return statement;}public void setStatement(String statement) { this.statement=statement; Log.i("This is the statement:", statement);}public String getPromises() { return promises;}public void setPromises(String promises) { this.promises = promises;}\[/code\]}
 
Back
Top