[jdom-interest] Problem getting my XML in
Edd Dawson
E.J.Dawson at derby.ac.uk
Wed Aug 18 10:33:14 PDT 2004
Hi
I am developing some code in Java to access to a publicly accessible
gene database via simple URL's and import the XML into a parser all
using Jdom..
the code is as follows :
=============================================================
package PJB;
/**
* <p>Title: PjbImportCentre </p>
* <p>Description: Class for importing data from Entrez gene</p>
* <p>Copyright: Copyright MitchellConnerSearson Ltd(c) 2004</p>
* <p>Company: MitchellConnerSearson </p>
* @author Edd Dawson
* @version 1.0
*/
import java.net.*;
import java.util.*;
import java.io.*;
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
import org.jdom.input.SAXBuilder;
public class PjbImportCentre {
private URL urlObj;
//URL of the webservice which provides data
private final static String EG_URL =
"http://www.ncbi.nlm.gov/entrez/query.fcgi?cmd=text&";
/**
* Constructor for McsCheckerCentre Objects.
*
* Creates new instance of McsCheckerCentre
*
*
*/
public PjbImportCentre()
{
}
/**
*Gets the xml file for a specific gene uid
*
*@param uid String = the uid of the gene you wish to get
*
*@return
**/
public String getGene(String uid) {
String xml = "db=gene&dopt=xml&uid=" + uid;
try {
//--------open connection to the xml gateway
URL urlObj = new URL(EG_URL + xml);
SAXBuilder builder = new SAXBuilder();
Document doc = null;
try {
doc = builder.build(urlObj);
}
catch(Exception ex) {
return "Error on making xml returned SAXable" +
ex.getMessage();
}
String geneTrackGeneId =
doc.getRootElement().getChild("Entrezgene_track-info").getChild("Gene-track").getChild("Gene-track_geneid").getTextTrim();;
return geneTrackGeneId;
}
catch(Exception ex) {
return "error on POST : " + ex.getMessage();
}
}
}
================================================================================
I have a little bit of code to run the class as follows ;
================================================================================
import PJB.*;
class Pjb {
private void doExample(String search) {
PjbImportCentre xmlExample = new PjbImportCentre();
System.out.println(xmlExample.getGene(search));
}
public static void main(String[] args) {
Pjb test = new Pjb();
test.doExample(args[0]);
}
}
========================================================================
when i run the code as follows :
c:\PJB\java Pjb 4537
i get the following result
"Error on making xml returned SAXable null"
If i pull back the XML from a browser it starts like this :
<?xml version="1.0"?>
<!DOCTYPE Entrezgene PUBLIC "-//NCBI//NCBI Entrezgene/EN"
"NCBI_Entrezgene.dtd">
<Entrezgene>
<Entrezgene_track-info>
<Gene-track>
<Gene-track_geneid>4537</Gene-track_geneid>
<Gene-track_create-date>
<Date>
(for the full document just go to
http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=text&db=gene&dopt=xml&uid=4537)
I am wondering why this is happening, it would appear to be that there
is a problem with the XML being returned if the parser is rejecting it.
Does anyone have any experience of this happening before?
thanks
Edd Dawson
More information about the jdom-interest
mailing list