Nokogiri each node do, Ruby -


i have 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"/> 

how can see first node kapitel . kapitel.each |f| nokgiri extrakts nodes von_icd_code , bis_icd_code in right order. code:

    require 'rubygems'     require 'nokogiri'        require 'open-uri'   @doc = nokogiri::xml(file.open("icd.xml"))    kapitel = @doc.css('kapitel')    kapitel.each |f|     puts f.css('von_icd_code')       puts f.css('bis_icd_code')      end 

the problem nogiri not extrakt 'von_icd_code' , 'bis_icd_code' in right oder, instead first list von_icd_code , 'bis_icd_code'. how can extrakt nodes in right oder?

and in output get:

<von_icd_code v="a00"/> 

how can content of v in case a00

thanks!

since bis_icd_code follows each von_icd_code, obvious choice css's + next adjacent sibling selector:

doc.css('von_icd_code').each |icd|   puts icd['v']   puts icd.at('+ bis_icd_code')['v'] end #=> a00 #=> b99 #=> a00 #=> a09 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -