Results 1 to 2 of 2
- 04-01-2012, 05:44 AM #1
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Unmarshalling Restful Xml response
I built a Bing Search API client using swing. I get the xml back which I store in a String and write to a JScrollPane.
I want to be able to display the info in a "useful" manner in JTextArea Like:Java Code:public static String HttpGetString(String urlString) throws IOException { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); if(conn.getResponseCode() != 200) { throw new IOException(); } BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while((line = reader.readLine()) != null) { builder.append(line); } reader.close(); conn.disconnect(); return builder.toString(); }//end of HttpGetString
Store name: Walmart
address: 123 main st
city: Whereverville
State: Confusion
Zip: 11111
So do I have to create classes for each element in the hierarchy and then use JAXB? Does JAXB know how to unmarshall into classes given the elements in the XML?
I have looked at Xstream and JAXB and cannot figure out where to go. The other problem is that they all read from a file not a String. Is there a better implementation for consuming RESTful Xml,
where a built-in-class/method handles the low level work with the xml, or do I have to examine the xml and write classes from the structure I see? Also how to you parse the initial part of the response:
thanks in advance!Java Code:<?xml version="1.0" encoding="UTF-8"?> <?pageview_candidate ?> -<SearchResponse Version="2.2" xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element">-<Query><SearchTerms>walmart</SearchTerms></Query>
- 04-01-2012, 06:19 AM #2
Similar Threads
-
SOAP|Java Response - IOException| Server response - a:System.Net.WebException
By bornster in forum XMLReplies: 0Last Post: 04-07-2011, 03:09 PM -
JAXB Unmarshalling
By milan.nosal in forum XMLReplies: 0Last Post: 09-01-2010, 02:15 PM -
RESTful Web Service
By aakinn in forum New To JavaReplies: 0Last Post: 04-13-2010, 04:06 PM -
JAXB: Unmarshalling does not always populate certain classes?
By queuetip in forum XMLReplies: 0Last Post: 02-22-2010, 05:15 AM -
JAXB Unmarshalling
By prateek in forum XMLReplies: 0Last Post: 07-10-2008, 06:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks