Pregunta

I don't know if I'm parsing in correctly or if i'm printing out incorrectly from a the hashmap? I think i must be parsing incorrectly because when I check the values I get null.

main.java

public static void main(String[] args) throws Exception
    { 
        SAXParserFactory spf = SAXParserFactory.newInstance(); 
        SAXParser sp = spf.newSAXParser(); 
        XMLReader xr = sp.getXMLReader(); 
        xr.setContentHandler(new DrugbankHandler()); 
        xr.parse("c:\\drugbank.xml");
      System.out.println(DrugbankHandler.lookupCache);
       // DrugbankHandler.printMap();

contenthandler.java

public class DrugbankHandler implements ContentHandler {

    boolean drugFound;
    boolean nameFound;
    boolean drugInteraction;
    boolean drugID;
    boolean packager;
    boolean calculatedProperties;
    boolean kindFound;
    boolean inChiKeyValueFound;
    boolean nextValueIsInChiKey;
    boolean isSmallMolecule;
    boolean property;
    boolean previousTagWasDrugID;

    DrugModel tempDrugModel;

    /**
     * stores key (drugbank-id), value (drug model) pairs
     */
    public final static  HashMap<String, DrugModel> lookupCache = new HashMap<String, DrugModel>(
            7000);

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes atts) throws SAXException {

        //System.out.print(atts); 
        if (tempDrugModel != null && tempDrugModel.drugbankID.equals("DB00002")) {
            System.out.println(localName);
            if (localName.equals("value")) {
                System.out.print("");
            }
        }

        if (localName.equals("drug-interaction")) {
            drugInteraction = true;
            return;
        }

        if (localName.equals("drug") && !drugInteraction
                && atts.getLength() > 0) {
            if (atts.getValue("type").equals("biotech"))
                return;
            drugFound = true;
            tempDrugModel = new DrugModel();
            String type = atts.getValue("type");
            if (type.startsWith("small"))
                isSmallMolecule = true;
            else
                isSmallMolecule = false;

            tempDrugModel.isSmallMolecule = isSmallMolecule;

            return;
        }
        if (localName.equals("drugbank-id")) {
            drugID = true;
            return;
        }
        if (previousTagWasDrugID && localName.equals("name")) {
            nameFound = true;
            return;
        }
        // if drug is a small molecule read its InChIKey value
        /**
         * <calculated-properties> <property> <kind>InChI</kind>
         * <value>InChIKey=hurensohn</value> <source>JChem</source> </property>
         * .... </calculated-properties>
         */
        if (isSmallMolecule) {
            if (calculatedProperties && localName.equals("property")) {
                property = true;
                return;
            }
            if (property && localName.equals("kind")) {
                kindFound = true;
                return;
            }
            if (localName.equals("calculated-properties")) {
                calculatedProperties = true;
                return;
            }
            if (nextValueIsInChiKey && localName.equals("value")) {
                inChiKeyValueFound = true;
                nextValueIsInChiKey = false;
                return;
            }
        } else {
            // TODO which id or feature to lookup peptides in chembl?
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        if (drugFound && !drugInteraction && localName.equals("drug")) {
            drugFound = false;
            lookupCache.put(tempDrugModel.drugbankID, tempDrugModel);
            return;
        }

        if (localName.equals("drugbank-id")) {
            previousTagWasDrugID = true;
        }
        if (localName.equals("drug-interaction")) {
            drugInteraction = false;
        }
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        if (!drugFound)
            return;

        if (nameFound) {
            tempDrugModel.name = new String(ch, start, length);
            previousTagWasDrugID = false;
            nameFound = false;
            return;
        }
        if (drugID) {
            tempDrugModel.drugbankID = new String(ch, start, length);
            drugID = false;
            return;
        }
        if (kindFound) {
            String kind = new String(ch, start, length);
            if (kind.equals("InChIKey")) {
                nextValueIsInChiKey = true;
            }
            kindFound = false;
            return;
        }
        if (inChiKeyValueFound) {
            // skip the "InChIKey=" prefix of length 9
            String k = new String(ch, start + 9, length - 9);
            tempDrugModel.InChiKey = k;
            inChiKeyValueFound = false;
            return;
        }
    }


    public static void printMap() {
        /*Iterator it = lookupCache.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Integer key = (Integer)entry.getKey();
            String val = (String)entry.getValue();



            System.out.println(lookupCache);

        }*/
         System.out.println(lookupCache);
 } 
    // ignored methods following...

    @Override
    public void ignorableWhitespace(char[] ch, int start, int length)
            throws SAXException {
    }

    @Override
    public void processingInstruction(String target, String data)
            throws SAXException {
    }

    @Override
    public void skippedEntity(String name) throws SAXException {
    }

    @Override
    public void setDocumentLocator(Locator locator) {
    }

    @Override
    public void startDocument() throws SAXException {
    }

    @Override
    public void endDocument() throws SAXException {
    }

    @Override
    public void startPrefixMapping(String prefix, String uri)
            throws SAXException {
    }

    @Override
    public void endPrefixMapping(String prefix) throws SAXException {
    }
}

sample xml

<?xml version="1.0" encoding="UTF-8"?>
<drugs xmlns="http://drugbank.ca" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="2.0" xs:schemaLocation="http://www.drugbank.ca/docs/drugbank.xsd">
<drug type="biotech" created="2005-06-13 07:24:05 -0600" updated="2013-05-12 21:37:25 -0600" version="4.0">
  <drugbank-id>DB00001</drugbank-id>
  <name>Lepirudin</name>
  <description>Lepirudin is identical to natural hirudin except for substitution of leucine for isoleucine at the N-terminal end of the molecule and the absence of a sulfate group on the tyrosine at position 63. It is produced via yeast cells.&#13;
</description>
  <cas-number>120993-53-5</cas-number>
  <general-references># Smythe MA, Stephens JL, Koerber JM, Mattson JC: A comparison of lepirudin and argatroban outcomes. Clin Appl Thromb Hemost. 2005 Oct;11(4):371-4. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/16244762&#13;
# Tardy B, Lecompte T, Boelhen F, Tardy-Poncet B, Elalamy I, Morange P, Gruel Y, Wolf M, Francois D, Racadot E, Camarasa P, Blouch MT, Nguyen F, Doubine S, Dutrillaux F, Alhenc-Gelas M, Martin-Toutain I, Bauters A, Ffrench P, de Maistre E, Grunebaum L, Mouton C, Huisse MG, Gouault-Heilmann M, Lucke V: Predictive factors for thrombosis and major bleeding in an observational study in 181 patients with heparin-induced thrombocytopenia treated with lepirudin. Blood. 2006 Sep 1;108(5):1492-6. Epub 2006 May 11. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/16690967&#13;
# Lubenow N, Eichler P, Lietz T, Greinacher A: Lepirudin in patients with heparin-induced thrombocytopenia - results of the third prospective study (HAT-3) and a combined analysis of HAT-1, HAT-2, and HAT-3. J Thromb Haemost. 2005 Nov;3(11):2428-36. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/16241940&#13;
# Askari AT, Lincoff AM: Antithrombotic Drug Therapy in Cardiovascular Disease. 2009 Oct; pp. 440–. ISBN 9781603272346. "Google books":http://books.google.com/books?id=iadLoXoQkWEC&amp;pg=PA440. </general-references>
  <synthesis-reference/>
  <indication>For the treatment of heparin-induced thrombocytopenia</indication>
  <pharmacology>Lepirudin is used to break up clots and to reduce thrombocytopenia. It binds to thrombin and prevents thrombus or clot formation. It is a highly potent, selective, and essentially irreversible inhibitor of thrombin and clot-bond thrombin. Lepirudin requires no cofactor for its anticoagulant action. Lepirudin is a recombinant form of hirudin, an endogenous anticoagulant found in medicinal leeches.</pharmacology>
  <mechanism-of-action>Lepirudin forms a stable non-covalent complex with alpha-thrombin, thereby abolishing its ability to cleave fibrinogen and initiate the clotting cascade. The inhibition of thrombin prevents the blood clotting cascade. </mechanism-of-action>
  <toxicity>In case of overdose (eg, suggested by excessively high aPTT values) the risk of bleeding is increased.</toxicity>
  <biotransformation>Lepirudin is thought to be metabolized by release of amino acids via catabolic hydrolysis of the parent drug. However, con-clusive data are not available. About 48% of the administration dose is excreted in the urine which consists of unchanged drug (35%) and other fragments of the parent drug.</biotransformation>
  <absorption>Bioavailability is 100% following injection.</absorption>
  <half-life>Approximately 1.3 hours</half-life>
  <protein-binding/>
  <route-of-elimination>Lepirudin is thought to be metabolized by release of amino acids via catabolic hydrolysis of the parent drug. About 48% of the administration dose is excreted in the urine which consists of unchanged drug (35%) and other fragments of the parent drug.</route-of-elimination>
  <volume-of-distribution>* 12.2 L [Healthy young subjects (n = 18, age 18-60 years)]&#13;
* 18.7 L [Healthy elderly subjects (n = 10, age 65-80 years)]&#13;
* 18 L [Renally impaired patients (n = 16, creatinine clearance below 80 mL/min)]&#13;
* 32.1 L [HIT patients (n = 73)]</volume-of-distribution>
  <clearance>* 164 ml/min [Healthy 18-60 yrs]&#13;
* 139 ml/min [Healthy 65-80 yrs]&#13;
* 61 ml/min [renal impaired]&#13;
* 114 ml/min [HIT (Heparin-induced thrombocytopenia)]</clearance>
  <secondary-accession-numbers>
    <secondary-accession-number>BIOD00024</secondary-accession-number>
    <secondary-accession-number>BTD00024</secondary-accession-number>
  </secondary-accession-numbers>
  <groups>
    <group>approved</group>
  </groups>
  <taxonomy>
    <kingdom/>
    <substructures/>
  </taxonomy>
  <synonyms>
    <synonym>Hirudin variant-1</synonym>
  </synonyms>
  <salts/>
  <brands>
    <brand>Refludan</brand>
  </brands>
  <mixtures/>
  <packagers>
    <packager>
      <name>Bayer Healthcare</name>
      <url>http://www.bayerhealthcare.com</url>
    </packager>
    <packager>
      <name>Berlex Labs</name>
      <url>http://www.berlex.com</url>
    </packager>
  </packagers>
  <manufacturers>
    <manufacturer generic="false">Bayer healthcare pharmaceuticals inc</manufacturer>
  </manufacturers>
  <prices>
    <price>
      <description>Refludan 50 mg vial</description>
      <cost currency="USD">273.19</cost>
      <unit>vial</unit>
    </price>
  </prices>
  <categories>
    <category>Antithrombins</category>
    <category>Fibrinolytic Agents</category>
  </categories>
  <affected-organisms>
    <affected-organism>Humans and other mammals</affected-organism>
  </affected-organisms>
  <dosages>
    <dosage>
      <form>Powder, for solution</form>
      <route>Intravenous</route>
      <strength/>
    </dosage>
  </dosages>
  <atc-codes>
    <atc-code>B01AE02</atc-code>
    <category/>
  </atc-codes>
  <ahfs-codes>
    <ahfs-code>20:12.04.12</ahfs-code>
  </ahfs-codes>
  <patents>
    <patent>
      <number>5180668</number>
      <country>United States</country>
      <approved>1993-01-19</approved>
      <expires>2010-01-19</expires>
    </patent>
    <patent>
      <number>1339104</number>
      <country>Canada</country>
      <approved>1997-07-29</approved>
      <expires>2014-07-29</expires>
    </patent>
  </patents>
  <food-interactions/>
  <drug-interactions>
    <drug-interaction>
      <drug>DB01381</drug>
      <name>Ginkgo biloba</name>
      <description>Additive anticoagulant/antiplatelet effects may increase bleed risk. Concomitant therapy should be avoided.</description>
    </drug-interaction>
    <drug-interaction>
      <drug>DB00374</drug>
      <name>Treprostinil</name>
      <description>The prostacyclin analogue, Treprostinil, increases the risk of bleeding when combined with the anticoagulant, Lepirudin. Monitor for increased bleeding during concomitant thearpy. </description>
    </drug-interaction>
  </drug-interactions>
  <protein-sequences>
    <fasta>
      <fasta>#&lt;PolypeptideSequence:0x007f1d1efef190&gt;</fasta>
    </fasta>
  </protein-sequences>
  <experimental-properties>
    <property>
      <kind>Melting Point</kind>
      <value>65 °C</value>
      <source>Otto, A. &amp; Seckler, R. Eur. J. Biochem. 202:67-73 (1991)</source>
    </property>
    <property>
      <kind>Hydrophobicity</kind>
      <value>-0.777</value>
      <source/>
    </property>
    <property>
      <kind>Isoelectric Point</kind>
      <value>4.04</value>
      <source/>
    </property>
    <property>
      <kind>Molecular Weight</kind>
      <value>6963.4250</value>
      <source/>
    </property>
    <property>
      <kind>Molecular Formula</kind>
      <value>C287H440N80O110S6</value>
      <source/>
    </property>
  </experimental-properties>
  <external-identifiers>
    <external-identifier>
      <resource>Drugs Product Database (DPD)</resource>
      <identifier>2240996</identifier>
    </external-identifier>
    <external-identifier>
      <resource>KEGG Drug</resource>
      <identifier>D06880</identifier>
    </external-identifier>
    <external-identifier>
      <resource>National Drug Code Directory</resource>
      <identifier>50419-150-57</identifier>
    </external-identifier>
    <external-identifier>
      <resource>PharmGKB</resource>
      <identifier>PA450195</identifier>
    </external-identifier>
    <external-identifier>
      <resource>UniProtKB</resource>
      <identifier>P01050</identifier>
    </external-identifier>
    <external-identifier>
      <resource>Wikipedia</resource>
      <identifier>Lepirudin</identifier>
    </external-identifier>
  </external-identifiers>
  <external-links>
    <external-link>
      <resource>RxList</resource>
      <url>http://www.rxlist.com/cgi/generic/lepirudin.htm</url>
    </external-link>
    <external-link>
      <resource>Drugs.com</resource>
      <url>http://www.drugs.com/cdi/lepirudin.html</url>
    </external-link>
  </external-links>
  <targets>
    <target>
      <id>BE0000048</id>
      <name>Prothrombin</name>
      <organism>Human</organism>
      <actions>
        <action>inhibitor</action>
      </actions>
      <references># Turpie AG: Anticoagulants in acute coronary syndromes. Am J Cardiol. 1999 Sep 2;84(5A):2M-6M. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/10505536&#13;
# Warkentin TE: Venous thromboembolism in heparin-induced thrombocytopenia. Curr Opin Pulm Med. 2000 Jul;6(4):343-51. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/10912644&#13;
# Eriksson BI: New therapeutic options in deep vein thrombosis prophylaxis. Semin Hematol. 2000 Jul;37(3 Suppl 5):7-9. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11055889&#13;
# Fabrizio MC: Use of ecarin clotting time (ECT) with lepirudin therapy in heparin-induced thrombocytopenia and cardiopulmonary bypass. J Extra Corpor Technol. 2001 May;33(2):117-25. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11467439&#13;
# Szaba FM, Smiley ST: Roles for thrombin and fibrin(ogen) in cytokine/chemokine production and macrophage adhesion in vivo. Blood. 2002 Feb 1;99(3):1053-9. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11807012&#13;
# Chen X, Ji ZL, Chen YZ: TTD: Therapeutic Target Database. Nucleic Acids Res. 2002 Jan 1;30(1):412-5. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11752352</references>
      <known-action>yes</known-action>
      <components>
        <polypeptide id="P00734">
          <name>Prothrombin</name>
          <general-function>Involved in blood clotting cascade</general-function>
          <specific-function>Thrombin, which cleaves bonds after Arg and Lys, converts fibrinogen to fibrin and activates factors V, VII, VIII, XIII, and, in complex with thrombomodulin, protein C</specific-function>
          <gene-name>F2</gene-name>
          <locus>11p11-q12</locus>
          <cellular-location>Secreted protein; extracellular space</cellular-location>
          <transmembrane-regions>None</transmembrane-regions>
          <theoretical-pi>5.7</theoretical-pi>
          <molecular-weight>70037.0</molecular-weight>
          <chromosome-location/>
          <external-identifiers>
            <external-identifier>
              <resource>HUGO Gene Nomenclature Committee (HGNC)</resource>
              <identifier>HGNC:3535</identifier>
            </external-identifier>
            <external-identifier>
              <resource>GenAtlas</resource>
              <identifier>F2</identifier>
            </external-identifier>
            <external-identifier>
              <resource>GeneCards</resource>
              <identifier>F2</identifier>
            </external-identifier>
            <external-identifier>
              <resource>GenBank Gene Database</resource>
              <identifier>M17262</identifier>
            </external-identifier>
            <external-identifier>
              <resource>GenBank Protein Database</resource>
              <identifier>339641</identifier>
            </external-identifier>
            <external-identifier>
              <resource>UniProtKB</resource>
              <identifier>P00734</identifier>
            </external-identifier>
          </external-identifiers>
          <synonyms>
            <synonym>Activated Factor II [IIa]</synonym>
            <synonym>Coagulation factor II</synonym>
            <synonym>EC 3.4.21.5</synonym>
            <synonym>Prothrombin precursor</synonym>
            <synonym>Thrombin</synonym>
          </synonyms>
          <amino-acid-sequence>
            <fasta>&gt;Prothrombin precursor
MAHVRGLQLPGCLALAALCSLVHSQHVFLAPQQARSLLQRVRRANTFLEEVRKGNLEREC
VEETCSYEEAFEALESSTATDVFWAKYTACETARTPRDKLAACLEGNCAEGLGTNYRGHV
NITRSGIECQLWRSRYPHKPEINSTTHPGADLQENFCRNPDSSTTGPWCYTTDPTVRRQE
CSIPVCGQDQVTVAMTPRSEGSSVNLSPPLEQCVPDRGQQYQGRLAVTTHGLPCLAWASA
QAKALSKHQDFNSAVQLVENFCRNPDGDEEGVWCYVAGKPGDFGYCDLNYCEEAVEEETG
DGLDEDSDRAIEGRTATSEYQTFFNPRTFGSGEADCGLRPLFEKKSLEDKTERELLESYI
DGRIVEGSDAEIGMSPWQVMLFRKSPQELLCGASLISDRWVLTAAHCLLYPPWDKNFTEN
DLLVRIGKHSRTRYERNIEKISMLEKIYIHPRYNWRENLDRDIALMKLKKPVAFSDYIHP
VCLPDRETAASLLQAGYKGRVTGWGNLKETWTANVGKGQPSVLQVVNLPIVERPVCKDST
RIRITDNMFCAGYKPDEGKRGDACEGDSGGPFVMKSPFNNRWYQMGIVSWGEGCDRDGKY
GFYTHVFRLKKWIQKVIDQFGE</fasta>
          </amino-acid-sequence>
          <gene-sequence>
            <fasta>&gt;1869 bp
ATGGCGCACGTCCGAGGCTTGCAGCTGCCTGGCTGCCTGGCCCTGGCTGCCCTGTGTAGC
CTTGTGCACAGCCAGCATGTGTTCCTGGCTCCTCAGCAAGCACGGTCGCTGCTCCAGCGG
GTCCGGCGAGCCAACACCTTCTTGGAGGAGGTGCGCAAGGGCAACCTAGAGCGAGAGTGC
GTGGAGGAGACGTGCAGCTACGAGGAGGCCTTCGAGGCTCTGGAGTCCTCCACGGCTACG
GATGTGTTCTGGGCCAAGTACACAGCTTGTGAGACAGCGAGGACGCCTCGAGATAAGCTT
GCTGCATGTCTGGAAGGTAACTGTGCTGAGGGTCTGGGTACGAACTACCGAGGGCATGTG
AACATCACCCGGTCAGGCATTGAGTGCCAGCTATGGAGGAGTCGCTACCCACATAAGCCT
GAAATCAACTCCACTACCCATCCTGGGGCCGACCTACAGGAGAATTTCTGCCGCAACCCC
GACAGCAGCACCACGGGACCCTGGTGCTACACTACAGACCCCACCGTGAGGAGGCAGGAA
TGCAGCATCCCTGTCTGTGGCCAGGATCAAGTCACTGTAGCGATGACTCCACGCTCCGAA
GGCTCCAGTGTGAATCTGTCACCTCCATTGGAGCAGTGTGTCCCTGATCGGGGGCAGCAG
TACCAGGGGCGCCTGGCGGTGACCACACATGGGCTCCCCTGCCTGGCCTGGGCCAGCGCA
CAGGCCAAGGCCCTGAGCAAGCACCAGGACTTCAACTCAGCTGTGCAGCTGGTGGAGAAC
TTCTGCCGCAACCCAGACGGGGATGAGGAGGGCGTGTGGTGCTATGTGGCCGGGAAGCCT
GGCGACTTTGGGTACTGCGACCTCAACTATTGTGAGGAGGCCGTGGAGGAGGAGACAGGA
GATGGGCTGGATGAGGACTCAGACAGGGCCATCGAAGGGCGTACCGCCACCAGTGAGTAC
CAGACTTTCTTCAATCCGAGGACCTTTGGCTCGGGAGAGGCAGACTGTGGGCTGCGACCT
CTGTTCGAGAAGAAGTCGCTGGAGGACAAAACCGAAAGAGAGCTCCTGGAATCCTACATC
GACGGGCGCATTGTGGAGGGCTCGGATGCAGAGATCGGCATGTCACCTTGGCAGGTGATG
CTTTTCCGGAAGAGTCCCCAGGAGCTGCTGTGTGGGGCCAGCCTCATCAGTGACCGCTGG
GTCCTCACCGCCGCCCACTGCCTCCTGTACCCGCCCTGGGACAAGAACTTCACCGAGAAT
GACCTTCTGGTGCGCATTGGCAAGCACTCCCGCACAAGGTACGAGCGAAACATTGAAAAG
ATATCCATGTTGGAAAAGATCTACATCCACCCCAGGTACAACTGGCGGGAGAACCTGGAC
CGGGACATTGCCCTGATGAAGCTGAAGAAGCCTGTTGCCTTCAGTGACTACATTCACCCT
GTGTGTCTGCCCGACAGGGAGACGGCAGCCAGCTTGCTCCAGGCTGGATACAAGGGGCGG
GTGACAGGCTGGGGCAACCTGAAGGAGACGTGGACAGCCAACGTTGGTAAGGGGCAGCCC
AGTGTCCTGCAGGTGGTGAACCTGCCCATTGTGGAGCGGCCGGTCTGCAAGGACTCCACC
CGGATCCGCATCACTGACAACATGTTCTGTGCTGGTTACAAGCCTGATGAAGGGAAACGA
GGGGATGCCTGTGAAGGTGACAGTGGGGGACCCTTTGTCATGAAGAGCCCCTTTAACAAC
CGCTGGTATCAAATGGGCATCGTCTCATGGGGTGAAGGCTGTGACCGGGATGGGAAATAT
GGCTTCTACACACATGTGTTCCGCCTGAAGAAGTGGATACAGAAGGTCATTGATCAGTTT
GGAGAGTAG</fasta>
          </gene-sequence>
          <pfams>
            <pfam>
              <identifier>PF00594</identifier>
              <name>Gla</name>
            </pfam>
            <pfam>
              <identifier>PF00051</identifier>
              <name>Kringle</name>
            </pfam>
            <pfam>
              <identifier>PF00089</identifier>
              <name>Trypsin</name>
            </pfam>
          </pfams>
          <go-classifiers>
            <go-classifier>
              <id/>
              <category>component</category>
              <description>extracellular region</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>binding</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>catalytic activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>thrombin activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>hydrolase activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>calcium ion binding</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>peptidase activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>ion binding</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>endopeptidase activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>cation binding</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>function</category>
              <description>serine-type endopeptidase activity</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>protein metabolism</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>proteolysis</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>cellular protein metabolism</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>organismal physiological process</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>regulation of body fluids</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>physiological process</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>hemostasis</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>blood coagulation</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>metabolism</description>
            </go-classifier>
            <go-classifier>
              <id/>
              <category>process</category>
              <description>macromolecule metabolism</description>
            </go-classifier>
          </go-classifiers>
        </polypeptide>
      </components>
    </target>
  </targets>
  <enzymes/>
  <carriers/>
  <transporters/>
¿Fue útil?

Solución

Have you tried defining an XSD schema for the XML and using a JaxBContentHandler?

In my opinion is a much better implementation because:

  • You can also retrieve the results from the POJO objects you have unmarshalled.

  • If the XML format changes, you will only have to change the XSD schema and regenerate the POJO classes.

Only drawback I have seen is performance unmarshalling very big XML files.

Sample:

    // Create a JAXB context from the POJO classes (you should have defined the XSD before)
    final JAXBContext context = JAXBContext.newInstance(Drugs.class);

    Unmarshaller unmarshaller;
    unmarshaller = context.createUnmarshaller();
    unmarshaller.setSchema(null);
    // create a new XML parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XMLReader reader = factory.newSAXParser().getXMLReader();

    // JAXB marshaller
    reader.setContentHandler(unmarshaller.getUnmarshallerHandler());

    // This is the buffer from you are reading (i.e. this can be the XML file)
    reader.parse(new InputSource(inputBuffer));

    Drugs result = (Drugs) marshaller.getUnmarshallerHandler().getResult();
    // Now you can build a hashmap with the drugs you have retrieved
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top