Hello JItesh, this is a Firefox issue, not a Java related one. Either way, the solution is to drop leading whitespaces from your response.
With kind regards Ben On 1 Nov., 16:39, jitesh dundas <[email protected]> wrote: > Hi friends, > > I am getting this error on doing a post(using the code below) to this > url->http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&t... > > I have written this code in .jsp file. Later I will change it into servlet. > > Error:- > XML Parsing Error: XML or text declaration not at start of entity > Location:http://localhost:8080/ProteomDb/ImportFromPubmed2.jsp?txtDbName=pubme... > Line Number 11, Column 1:<?xml version="1.0" ?><!DOCTYPE eSearchResult > PUBLIC "-//NLM//DTD eSearchResult, 11 May 2002//EN" > "http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSearch_020511.dtd"><eSearchResult><Count>2034</Count><RetMax>20</RetMax><RetStart>0</RetStart><IdList> > <Id>19877350</Id> <Id>19877304</Id> <Id>19877297</Id> > <Id>19877284</Id> <Id>19877271</Id> <Id>19877265</Id> > <Id>19877250</Id> <Id>19877245</Id> <Id>19877226</Id> > <Id>19877210</Id> <Id>19877179</Id> <Id>19877175</Id> > <Id>19877161</Id> <Id>19877159</Id> <Id>19877158</Id> > <Id>19877123</Id> <Id>19877122</Id> <Id>19877120</Id> > <Id>19877119</Id> <Id>19877118</Id> > </IdList><TranslationSet><Translation> <From>cancer</From> > <To>"neoplasms"[MeSH Terms] OR "neoplasms"[All Fields] OR "cancer"[All > Fields]</To> </Translation></TranslationSet><TranslationStack> > <TermSet> <Term>"neoplasms"[MeSH Terms]</Term> <Field>MeSH > Terms</Field> <Count>2082133</Count> <Explode>Y</Explode> > </TermSet> <TermSet> <Term>"neoplasms"[All Fields]</Term> <Field>All > Fields</Field> <Count>1634731</Count> <Explode>Y</Explode> > </TermSet> <OP>OR</OP> <TermSet> <Term>"cancer"[All Fields]</Term> > <Field>All Fields</Field> <Count>902537</Count> <Explode>Y</Explode> > </TermSet> <OP>OR</OP> <OP>GROUP</OP> <TermSet> > <Term>2009/10/22[EDAT]</Term> <Field>EDAT</Field> <Count>0</Count> > <Explode>Y</Explode> </TermSet> <TermSet> > <Term>2009/11/01[EDAT]</Term> <Field>EDAT</Field> <Count>0</Count> > <Explode>Y</Explode> </TermSet> <OP>RANGE</OP> <OP>AND</OP> > </TranslationStack><QueryTranslation>("neoplasms"[MeSH Terms] OR > "neoplasms"[All Fields] OR "cancer"[All Fields]) AND 2009/10/22[EDAT] : > 2009/11/01[EDAT]</QueryTranslation></eSearchResult> > ^ > > As you can see, the XML output is coming fine but the above error does not > go..The output via this program should be just like hitting manually the > above URL in the browser.. > The browser is Mozilla Firefox. > > Code:- > > <%@ page language = "java" %> > <%@ page import = "java.sql.*" %> > <%@ page import = "java.util.*" %> > <%@ page import = "java.io.*" %> > <%@ page import="java.lang.*" %> > <%@ page import="java.net.*" %> > <%@ page import="java.nio.*" %> > <%@ page contentType="text/xml; charset=utf-8" pageEncoding="UTF-8" %> > > <% > > try > { > //String str = "<?xml version='1.0' ?>"; > //out.println("<?xml version='1.0' encoding='utf-8' ?>"); > > Properties systemSettings = System.getProperties(); > systemSettings.put("http.proxyHost", "********"); > systemSettings.put("http.proxyPort", "******"); > systemSettings.put("sun.net.client.defaultConnectTimeout", "10000"); > systemSettings.put("sun.net.client.defaultReadTimeout", "10000"); > > //out.println("Properties Set"); > Authenticator.setDefault(new Authenticator() > { > protected PasswordAuthentication getPasswordAuthentication() > { > return new PasswordAuthentication("**", > "******".toCharArray()); // specify ur user name password of iitb login > } > }); > > System.setProperties(systemSettings); > //out.println("After Authentication & Properties Settings"); > > //create xml file. > //the input to google api > //String textAreaContent = request.getParameter("text"); > String textAreaContent = "This si a tst"; > > String str = "<?xml version='1.0' encoding='utf-8' ?>"; > > //xml file generation ends here.. > //FetchDataFromNCBI_URLString.jsp > String URLString = request.getParameter("txtURLString").trim(); > > //URL url = new > URL("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=protein&... > "); > URL url = new URL(URLString); //url string taken from user input. > HttpURLConnection connection = null; > > connection = (HttpURLConnection) url.openConnection(); > System.out.println("After open connection"); > connection.setRequestMethod("POST"); > connection.setDoInput(true); > connection.setDoOutput(true); > > connection.setUseCaches(false); > connection.setAllowUserInteraction(false); > //connection.setFollowRedirects(true); > //connection.setInstanceFollowRedirects(true); > //System.out.println("Before-------------------"); > connection.setRequestProperty ("Content-Type","text/xml; > charset=\"utf-8\""); > //System.out.println("After-------------------"); > > //System.out.println(""+ connection.getOutputStream()); > > //System.out.println("After dataoutputstream..Line No-65"); > > //System.out.println("Response Code="+ connection.getResponseCode); > > OutputStreamWriter dosout = new > OutputStreamWriter(connection.getOutputStream()); > //System.out.println("After dosout object..Line No-63"); > //dosout.write(str); > dosout.close (); > > BufferedReader in = new BufferedReader( new InputStreamReader( > connection.getInputStream())); > > String decodedString; > String tempstr = ""; > > while ((decodedString = in.readLine()) != null) > { > tempstr = tempstr + decodedString; > //out.println(decodedString); > } > out.println(tempstr); > in.close();} > > catch(Exception ex) > { > out.println("Exception->"+ex); > PrintWriter pw = response.getWriter(); > ex.printStackTrace(pw); > > } > > %> > > Thanks in advance.. > > Regards, > JItesh Dundas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---
