Ho un file xml simile a questo:
codice:
<drugs>
    <drug>
            <drugbank-id> xxxxxxxx</drugbank-id>
            <name> xxxxxxxxxxxx </name>
            <description> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </description>
            <pharmacology> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</pharmacology>
    </drug>
    <drug>
             <drugbank-id> xxxxxxxx</drugbank-id>
            <name> xxxxxxxxxxxx </name>
            <description> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </description>
            <pharmacology> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</pharmacology>
    </drug>
</drugs>
e per parserizzare questo file xml ho scritto questo codice ruby

codice:
require 'rubygems'
require 'hpricot'

doc = Hpricot.parse(File.read('prova.xml'))
	(doc/:drug.).each do |drug|
		['drugbank-id', 'name', 'description', 'pharmacology'].each do |el|
			puts "#{doc.at(el).innerHTML}"
		end
	end
Mi stampa come risultato solo il primo drug senza andare nel secondo o il terzo etc etc....
tipo cosi:
codice:
DB00001
Lepirudin
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.&#xD;
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.
DB00001
Lepirudin
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.&#xD;
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.
DB00001
Lepirudin
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.&#xD;
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.
DB00001
Lepirudin
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.&#xD;
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.
Cioè il primo me lo stampa 4 volte anche se il file xml ha solo due drug.
Come mai? Dove sbaglio?
Ringrazio qualsiasi tipo di aiuto...scusate se ho postato qui ma non ho trovato la parte del forum di ruby.