How to use httpClient to filer parts of an xml file in Java

frieraBreeree

New Member
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:\[code\]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);\[/code\]The problem is that this code streams the entire XML file:\[code\]<?xml version="1.0"?><PC-Compoundxmlns="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">\[/code\]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:\[code\]cid = 5282253reader = 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")\[/code\](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:)
 
Back
Top