Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:29:05+00:00 2026-06-06T22:29:05+00:00

I am currently doing a project in which I have to request data from

  • 0

I am currently doing a project in which I have to request data from the metabolite database PubChem. I am using Apache’s HttpClient. I am doing the following:

HttpClient httpclient = new DefaultHttpClient();
HttpGet pubChemRequest = new HttpGet("http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid="
    + cid + "&disopt=SaveXML");
pubChemRequest.getAllHeaders();
System.out.println(pubChemRequest);
HttpResponse response = null;
response = httpclient.execute(pubChemRequest);
HttpEntity entity = response.getEntity();
pubChemInchi = EntityUtils.toString(entity);

The problem is that this code streams the entire XML file:

<?xml version="1.0"?>
<PC-Compound
xmlns="http://www.ncbi.nlm.nih.gov"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.ncbi.nlm.nih.gov ftp://ftp.ncbi.nlm.nih.gov/pubchem/specifications/pubchem.xsd">

etc.

What I want is that I can request, for example, the PubChem ID and it will paste the value that corresponds to that ID. I have found that this can be done with the native Java method, but I need to use the HttpClient for this.
With the native Java, it would be done like this:

cid = 5282253
reader = new PCCompoundXMLReader(
new URL("http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=" + cid + "&disopt=SaveXML").newInputStream())
mol = reader.read(new NNMolecule())
println "CID: " + mol.getProperty("PubChem CID")

(Note: This piece of code was written in Groovy, but it also works in Java after some adjustments)

So, if anyone can help me out, that would be great:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:29:06+00:00Added an answer on June 6, 2026 at 10:29 pm

    There are multiple ways to do this.

    If you want to turn the response into a bean and dont expect the the structure of the response to change I’d look at using XStream.
    Another option is using the SAX parser directly.

    Ofcourse the quick and dirty approach is to turn your responses content into a bufferedReader. Then feed that reader into the XMLReader you are using.

    An example using you code from above would be:

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet pubChemRequest = new HttpGet("http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid="
        + cid + "&disopt=SaveXML");
    pubChemRequest.getAllHeaders();
    System.out.println(pubChemRequest);
    HttpResponse response = null;
    response = httpclient.execute(pubChemRequest);
    BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
    cid = 5282253
    reader = new PCCompoundXMLReader(br)
    mol = reader.read(new NNMolecule())
    println "CID: " + mol.getProperty("PubChem CID")
    

    Googling for RESTful webservice clients or XMLReaders should give you plenty more information on this subject

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently doing a project where I have to interact with a circuit I
I have this interesting obstacle on my project. I am currently doing a MVC3
I'm currently doing a steganography project (for myself). I have done a bit of
I currently have a .csv file with several unlabeled columns of data, which to
I'm currently working on a project which uses many ajax requests to access data
I am currently working on a project which I think using soap as part
I'm currently doing a project in C# working with windows forms. During the course
I am new to Entity Framework. I am currently doing a project in ASP.NET,
I'm currently trying to teach myself PHP by doing a small image-processing type project
I'm currently doing facebook integration and have gone through this tutorial . So far,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.