Results 1 to 2 of 2
  1. #1
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Rep Power

    Default 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.
    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)
    		return builder.toString();
    	}//end of HttpGetString
    I want to be able to display the info in a "useful" manner in JTextArea Like:

    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:
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?pageview_candidate ?>
    -<SearchResponse Version="2.2" xmlns="">-<Query><SearchTerms>walmart</SearchTerms></Query>
    thanks in advance!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Unmarshalling Restful Xml response

    Append a newline "\n" after each line

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 0
    Last Post: 04-07-2011, 03:09 PM
  2. JAXB Unmarshalling
    By milan.nosal in forum XML
    Replies: 0
    Last Post: 09-01-2010, 02:15 PM
  3. RESTful Web Service
    By aakinn in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 04:06 PM
  4. Replies: 0
    Last Post: 02-22-2010, 06:15 AM
  5. JAXB Unmarshalling
    By prateek in forum XML
    Replies: 0
    Last Post: 07-10-2008, 06:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts