I have this xml:
<kapitel> <nummer V="1"/> <von_icd_code V="A00"/> <bis_icd_code V="B99"/> <bezeichnung V="Bestimmte infektiöse und parasitäre Krankheiten"/> <gruppen_liste> <gruppe> <von_icd_code V="A00"/> <bis_icd_code V="A09"/> <bezeichnung V="Infektiöse Darmkrankheiten"/> <diagnosen_liste> <diagnose> <icd_code V="A00.-"/> <bezeichnung V="Cholera"/> <abrechenbar V="n"/> <krankheit_in_mitteleuropa_sehr_selten V="j"/> <schlüsselnummer_mit_inhalt_belegt V="j"/> <infektionsschutzgesetz_meldepflicht V="j"/> <infektionsschutzgesetz_abrechnungsbesonderheit V="j"/>
As you can see, my first node is kapitel . I would like to do something like kapitel .each do | f | so nokgiri extracts the nodes von_icd_code and bis_icd_code in the correct order. My code is:
require 'rubygems' require 'nokogiri' require 'open-uri' @doc = Nokogiri::XML(File.open("icd.xml")) kapitel = @doc.css('kapitel') kapitel.each do |f| puts f.css('von_icd_code') puts f.css('bis_icd_code') end
The problem is that nogiri does not increment "von_icd_code" and "bis_icd_code" on the right side, instead, it first lists all von_icd_code and then all "bis_icd_code". How can I extract the nodes on the right?
And in my release, I get:
<von_icd_code V="A00"/>
How can I get the contents of V in this case A00
Thanks!
source share