java - dom4j not loading through entire xml -
i doing project downloads weather yahoo! weather rss feed , writing database. links yahoo! weather: http://weather.yahooapis.com/forecastrss?p=95129 problem right it's not loading tag. can read other parts kinda stops after astronomy tag. can tell me why not working? (also, using hibernate , jpa)
here code:
public void testbasicusage() { url myurl; document document; element root; weather weather = new weather(); try { myurl = new url("http://weather.yahooapis.com/forecastrss?p=95129"); document = parse(myurl); root = document.getrootelement(); element row; iterator itr; (iterator = root.elementiterator(); i.hasnext();) { row = (element) i.next(); itr = row.elementiterator(); while (itr.hasnext()) { element child = (element) itr.next(); if(child.getqualifiedname().equals("yweather:location")){ string location = child.attributevalue("city") + ", " + child.attributevalue("region"); weather.setlocation(location); system.out.println("location: " + location); }else if(child.getqualifiedname().equals("yweather:wind")){ string chill = child.attributevalue("chill"); int direction = integer.parseint(child.attributevalue("direction")); int speed = integer.parseint(child.attributevalue("speed")); wind wind = new wind(chill,direction,speed); weather.setwind(wind); system.out.println("chill: " + chill + "; direction: " + direction + "; speed: " + speed); }else if(child.getqualifiedname().equals("yweather:atmosphere")){ int humidity = integer.parseint(child.attributevalue("humidity")); int visibility = integer.parseint(child.attributevalue("visibility")); double pressure = double.parsedouble(child.attributevalue("pressure")); atmosphere atmosphere = new atmosphere(humidity,visibility,pressure); weather.setatmosphere(atmosphere); system.out.println("humidity: " + humidity + "; visibility: " + visibility + "; pressure: " + pressure); }else if(child.getqualifiedname().equals("yweather:astronomy")){ string sunrise = child.attributevalue("sunrise"); string sunset = child.attributevalue("sunset"); astronomy astronomy = new astronomy(sunrise,sunset); weather.setastronomy(astronomy); system.out.println("sunrise: " + sunrise + "; sunset: " + sunset); }else if(child.getqualifiedname().equals("yweather:condition")){ string text = child.attributevalue("text"); // condition text int code = integer.parseint(child.attributevalue("code")); int temp = integer.parseint(child.attributevalue("temp")); string date = child.attributevalue("date"); condition condition = new condition(text,code,temp,date); weather.setcondition(condition); system.out.println("text: " + text + "; temp: " + temp + "; date: " + date); } } } entitymanager entitymanager = entitymanagerfactory.createentitymanager(); entitymanager.gettransaction().begin(); entitymanager.persist(weather); entitymanager.gettransaction().commit(); entitymanager.close(); } catch (exception e) { e.printstacktrace(); } } public document parse(url url) throws documentexception { saxreader reader = new saxreader(); document document = reader.read(url); return document; }
and fyi, testbasicusage() testcase function run junit.
thanks in advance!
you not handling tags after <yweather:astronomy>
. rest of data inside <item>
and <image>
tags:
else if (child.getqualifiedname().equals("item")){ string title = child.elementtext("title"); system.out.println("title: " + title); }
Comments
Post a Comment