ERROR Parsing xml from EAN using java



I'm trying to retrieve information from the EAN API. But i keep receiving the "Content is not allowed in prolog" error.



URL url = null;
InputStream is = null;
SAXBuilder builder = null;
Document doc = null;
Element root = null;

try {
String query= "http://ift.tt/1ufcAeN;" +
"minorRev=20&apiKey=fhmj76udakf3upamm5sk9qmr&locale=en_US&currencyCode=USD&latitude="
+ lat + "&longitude=" + lng + "&xml=<HotelListRequest><numberOfResults>10</numberOfResults></HotelListRequest>";


url = new URL(query);
is = url.openStream();
builder = new SAXBuilder();
doc = builder.build(is);

root = doc.getRootElement();
List<Element> HotelList = root.getChildren("HotelList");
Element Hotel = HotelList.get(0);
List<Element> SummaryList = Hotel.getChildren("HotelSummary");
Element Summary;
String[] names = new String [SummaryList.size()];
String[] addresses = new String[SummaryList.size()];
String[] hotelRatings = new String[SummaryList.size()];
String[] highRates = new String[SummaryList.size()];
String[] lowRates = new String[SummaryList.size()];

for (int i=0; i< SummaryList.size(); i++) {
Summary = SummaryList.get(i);
names[i] = Summary.getChildText("name");
addresses[i] = Summary.getChildText("address1");
addresses[i] += Summary.getChildText("address2");
hotelRatings[i] = Summary.getChildText("hotelRating");
highRates[i] = Summary.getChildText("highRate");
lowRates[i] = Summary.getChildText("lowRate");
}


That's my code. I really don't understand what's missing. Maybe someone could give a hint, or help. I've been trying to figure this out the whole day and it's making me crazy. Any help will be appreciated.


No comments:

Post a Comment