XML Parsing from an input stream Java

Pteradon

New Member
Hi everyone am currently working on an application that needs to parse an xml document so as to authenticate users.Am using URLConnection class of the java.net.* package to connect to as specific URL which gives an returns its response in xml format. When i try to parse the document using jdom , i get the following error --- > org.jdom2.input.JDOMParseException: Error on line 1: Premature end of fileCan anyone pinpoint the problem and assist me with a remedy? thanks, here is a section of my codetry{ String ivyString = "http://kabugi.hereiam.com/?username="+vyUsername+"&password="+ivyPassword; \[code\] URL authenticateURL = new URL(ivyString); URLConnection ivyConnection = authenticateURL.openConnection(); HttpURLConnection ivyHttp = (HttpURLConnection)ivyConnection; System.out.println("Response code ==>" + ivyHttp.getResponseCode()); if(ivyHttp.getResponseCode()!=200){ ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid username or password!", "")); page="confirm.xhtml"; } else{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(ivyConnection.getInputStream())); String inline=""; while((inline=inputReader.readLine())!=null){ System.out.println(inline); } SAXBuilder builder = new SAXBuilder(); Document document = (Document)builder.build(ivyConnection.getInputStream()); Element rootNode = document.getRootElement(); List list = rootNode.getChildren("data"); for(int i=0;i<list.size();i++){ Element node = (Element)list.get(i); System.out.println("Element data =http://stackoverflow.com/questions/12466529/=>" +node.getChildText("username")); System.out.println("Element data =http://stackoverflow.com/questions/12466529/=>" +node.getChildText("password")); } page="home.xhtml"; } } catch(Exception ex){ ex.printStackTrace(); // ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid username or password!", "")); }\[/code\]
 
Back
Top