Parse XML doc from url with ruby -


i not familiar xml , learning ruby go. problem having xml file using formatted different examples out there. attempting nokogiri seems popular of doing this.

my xml file url , looks this

<guides of="xml" rtn="5" tot="10" cv="1" a="xpu_nextstep" id="0" " w="" q="" g="echo" gr="homerec" gt="doc" js_q="" token="0:1qeu|5ig|557|1y7p|4re|">   <r t="orbelle toddler bed - cappuccino" g="echo" s="1" rk="1" pt="0" at="0" pr="0" ar="0">    <a n="onsale" v="yes"/>    <a n="sku" v="oti041"/>     <display>       <thumb n="imagename" v="http://images/mgen/master:oti041.jpg?is=400,400"/>       <labels>         <l n="saleprice" v="sale price: 69.98"/>         <l n="catname" v="toddler beds"/>         <l n="id" v="oti041"/>       </labels>     </display>   </r>   <r t="the orbelle contemporary solid wood toddler bed - cappuccino" g="xpu_nextstep" tm="bed, toddler, toddler bed, orbelle contemporary solid wood toddler bed cappuccino, toddler beds" s="0.4688" rk="2" pt="873" at="0" pr="0" ar="0">    <a n="availabledomain" v="toddlerbeds,kidsfurnituremart"/>    <a n="deptname" v="kids"/>    <a n="onsale" v="yes"/>    <a n="sku" v="oti029"/>    <a n="nichecategory" v="kids beds,standard toddler beds"/>     <display>      <thumb n="imagename" v="http://images/mgen/master:oti029.jpg?is=400,400"/>       <labels>         <l n="saleprice" v="sale price: 59.98"/>         <l n="catname" v="toddler beds"/>       </labels>     </display>  </r> 

i trying grab v="oti041" under each

right able open file with-

doc = nokogiri::xml(open("http://www.somesite.com")) 

use xpath:

doc.xpath('//r/a[@n="sku"]/@v').each {|x| puts x.value } 

also, note have syntax error in first line, @ ... id="0" " ...


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -