java error while parsing xml file from url -
java error while parsing xml file from url -
this question has reply here:
unable extract xml info website using java 1 replyi trying parse xml file in java facing problem. code showing error in parsing process if getting json file. how can solve issue ?
url url2 = new url("https://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55505&minorrev=99&apikey=cbrzfta369qwyrm9t5b8y8kf&locale=en_us¤cycode=usd&longitude=0.1275&latitude=51.5072&xml=%3chotellistrequest%3e%0a%20%20%20%20%3ccity%3eseattle%3c%2fcity%3e%0a%20%20%20%20%3cstateprovincecode%3ewa%3c%2fstateprovincecode%3e%0a%20%20%20%20%3ccountrycode%3eus%3c%2fcountrycode%3e%0a%20%20%20%20%3carrivaldate%3e11%2f25%2f2014%3c%2farrivaldate%3e%0a%20%20%20%20%3cdeparturedate%3e11%2f27%2f2014%3c%2fdeparturedate%3e%0a%20%20%20%20%3croomgroup%3e%0a%20%20%20%20%20%20%20%20%3croom%3e%0a%20%20%20%20%20%20%20%20%20%20%20%20%3cnumberofadults%3e2%3c%2fnumberofadults%3e%0a%20%20%20%20%20%20%20%20%3c%2froom%3e%0a%20%20%20%20%3c%2froomgroup%3e%0a%20%20%20%20%3cnumberofresults%3e25%3c%2fnumberofresults%3e%0a%3c%2fhotellistrequest%3e"); inputstream is2 = url2.openstream(); saxbuilder builder = new saxbuilder(); document doc = builder.build(is2); stringbuilder sb = new stringbuilder(); element root = doc.getrootelement(); list<element> hotellist = root.getchildren("hotellist"); element hotel = hotellist.get(0); list<element> summarylist = hotel.getchildren("hotelsummary"); element summary = summarylist.get(0); element sum; for(int f=0; f< summarylist.size(); f++){ sum = summarylist.get(f); sb.append("hotel id: " + sum.getchildtext("hotelid") +"\n" + "name: " + sum.getchildtext("name") + "\n"); sb.append("hotelrating: " + sum.getchildtext("hotelrating")+ "\n"); }system.out.println(sb);
the error:
org.jdom2.input.jdomparseexception: error on line 1: content not allowed in prolog. @ org.jdom2.input.sax.saxbuilderengine.build(saxbuilderengine.java:232) @ org.jdom2.input.sax.saxbuilderengine.build(saxbuilderengine.java:253) @ org.jdom2.input.saxbuilder.build(saxbuilder.java:1091) @ hotelinfo.main(hotelinfo.java:22) caused by: org.xml.sax.saxparseexception; linenumber: 1; columnnumber: 1; content not allowed in prolog. @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.createsaxparseexception(unknown source) @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.fatalerror(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlscanner.reportfatalerror(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl$prologdriver.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse(unknown source) @ org.jdom2.input.sax.saxbuilderengine.build(saxbuilderengine.java:217) ... 3 more
take @ returned info using curl
. json, not xml, hence cannot parse way. utilize json parser instead, or figure out api parameter needed create service homecoming xml.
java xml json jdom
Comments
Post a Comment