Ho dato un' occhiata ad un esempio di parsing di XML, č questo:

codice:
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ReadXMLFile {

 public static void main(String argv[]) {

  try {
  File file = new File("MyXMLFile.xml");
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document doc = db.parse(file);
  doc.getDocumentElement().normalize();
  System.out.println("Root element " + doc.getDocumentElement().getNodeName());
  NodeList nodeLst = doc.getElementsByTagName("employee");
  System.out.println("Information of all employees");

  for (int s = 0; s < nodeLst.getLength(); s++) {

    Node fstNode = nodeLst.item(s);
    
    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
  
           Element fstElmnt = (Element) fstNode;
      NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("firstname");
	    
      Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
      NodeList fstNm = fstNmElmnt.getChildNodes();
      System.out.println("First Name : "  + ((Node) fstNm.item(0)).getNodeValue());
      NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
      Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
      NodeList lstNm = lstNmElmnt.getChildNodes();
      System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
    }

  }
  } catch (Exception e) {
    e.printStackTrace();
  }
 }
}

Il codice mi č abbastanza chiaro, tranne il perchč dell' istruzione:

codice:
 NodeList fstNm = fstNmElmnt.getChildNodes();
      System.out.println("First Name : "  + ((Node) fstNm.item(0)).getNodeValue());
Ho sperimentato che non funziona, ma perchč non č possibile fare:

codice:
 Node fstNmElmnt =  fstNmElmntLst.item(0);
che tanto sarą un nodo, quello che mi interessa, e poi nella System stampo il suo valore?


Ora...in realtą il mio problema č un altro....se io ho un XML in questa forma:

codice:
<targets>
      <target position="1" partner="844">
        <actions>
          <action>antagonist</action>
        </actions>
        <references># Hosokawa N, Yamamoto S, Uehara Y, Hori M, Tsuchiya KS: Effect of thiazinotrienomycin B, an ansamycin antibiotic, on the function of epidermal growth factor receptor in human stomach tumor cells. J Antibiot (Tokyo). 1999 May;52(5):485-90. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/10480573&#xD;
# Wakita H, Takigawa M: Activation of epidermal growth factor receptor promotes late terminal differentiation of cell-matrix interaction-disrupted keratinocytes. J Biol Chem. 1999 Dec 24;274(52):37285-91. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/10601294&#xD;
# Suwa T, Ueda M, Jinno H, Ozawa S, Kitagawa Y, Ando N, Kitajima M: Epidermal growth factor receptor-dependent cytotoxic effect of anti-EGFR antibody-ribonuclease conjugate on human cancer cells. Anticancer Res. 1999 Sep-Oct;19(5B):4161-5. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/10628369&#xD;
# Burke P, Schooler K, Wiley HS: Regulation of epidermal growth factor receptor signaling by endocytosis and intracellular trafficking. Mol Biol Cell. 2001 Jun;12(6):1897-910. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11408594&#xD;
# Viloria-Petit A, Crombet T, Jothy S, Hicklin D, Bohlen P, Schlaeppi JM, Rak J, Kerbel RS: Acquired resistance to the antitumor effect of epidermal growth factor receptor-blocking antibodies in vivo: a role for altered tumor angiogenesis. Cancer Res. 2001 Jul 1;61(13):5090-101. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/11431346&#xD;
# 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>
      </target>
      <target position="2" partner="1102">
        <actions/>
        <references># Snyder LC, Astsaturov I, Weiner LM: Overview of monoclonal antibodies and small molecules targeting the epidermal growth factor receptor pathway in colorectal cancer. Clin Colorectal Cancer. 2005 Nov;5 Suppl 2:S71-80. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/16336752</references>
        <known-action>unknown</known-action>
      </target>
      <target position="3" partner="3814">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="4" partner="3815">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="5" partner="3816">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="6" partner="3817">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="7" partner="3818">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423&#xD;
# Zhang W, Gordon M, Schultheis AM, Yang DY, Nagashima F, Azuma M, Chang HM, Borucka E, Lurje G, Sherrod AE, Iqbal S, Groshen S, Lenz HJ: FCGR2A and FCGR3A polymorphisms associated with clinical outcome of epidermal growth factor receptor expressing metastatic colorectal cancer patients treated with single-agent cetuximab. J Clin Oncol. 2007 Aug 20;25(24):3712-8. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17704420</references>
        <known-action>unknown</known-action>
      </target>
      <target position="8" partner="2782">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="9" partner="784">
        <actions/>
        <references># Negri DR, Tosi E, Valota O, Ferrini S, Cambiaggi A, Sforzini S, Silvani A, Ruffini PA, Colnaghi MI, Canevari S: In vitro and in vivo stability and anti-tumour efficacy of an anti-EGFR/anti-CD3 F(ab')2 bispecific monoclonal antibody. Br J Cancer. 1995 Oct;72(4):928-33. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/7547242</references>
        <known-action>unknown</known-action>
      </target>
      <target position="10" partner="3819">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423&#xD;
# Zhang W, Gordon M, Schultheis AM, Yang DY, Nagashima F, Azuma M, Chang HM, Borucka E, Lurje G, Sherrod AE, Iqbal S, Groshen S, Lenz HJ: FCGR2A and FCGR3A polymorphisms associated with clinical outcome of epidermal growth factor receptor expressing metastatic colorectal cancer patients treated with single-agent cetuximab. J Clin Oncol. 2007 Aug 20;25(24):3712-8. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17704420</references>
        <known-action>unknown</known-action>
      </target>
      <target position="11" partner="3820">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
      <target position="12" partner="3821">
        <actions/>
        <references># Overington JP, Al-Lazikani B, Hopkins AL: How many drug targets are there? Nat Rev Drug Discov. 2006 Dec;5(12):993-6. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17139284&#xD;
# Imming P, Sinning C, Meyer A: Drugs, their targets and the nature and number of drug targets. Nat Rev Drug Discov. 2006 Oct;5(10):821-34. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/17016423</references>
        <known-action>unknown</known-action>
      </target>
    </targets>
In cui io devo prendere gli elementi del tipo:

codice:
<target position="1" partner="844">
Ed in particolare solo il valore numerico di partner....sbaglio o l' esempio precedente non mi aiuta visto che mi permette di estrarre valori compresi tra tag aperti e chiusi?