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:
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();
while((line = reader.readLine()) != null)
}//end of HttpGetString
Store name: Walmart
address: 123 main st
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!
<?xml version="1.0" encoding="UTF-8"?>
-<SearchResponse Version="2.2" xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element">-<Query><SearchTerms>walmart</SearchTerms></Query>
Re: Unmarshalling Restful Xml response
Append a newline "\n" after each line