开发者

Nokogiri/Ruby array question

I have a quick question. I am currently writing a Nokogiri/Ruby script and have the following code:

fullId = doc.xpath("/success/data/annotatorResultBean/annotations/annotationBean/concept/fullId")
fullId.each do |e|
            e = e.to_s()
            g.write(e + "\n")
    end

This spits out the f开发者_StackOverflow社区ollowing text:

<fullId>D001792</fullId>
<fullId>D001792</fullId>
<fullId>D001792</fullId>
<fullId>D008715</fullId>

I wanted the just the numbers text in between the "< fullid>" saved, without the < fullId>,< /fullId> markup. What am I missing?

Bobby


I think you want to use the text() accessor (which returns the child text values), rather than to_s() (which serializes the entire node, as you see here).

I'm not sure what the g object you're calling write on is, but the following code should give you an array containing all of the text in the fullId nodes:

doc.xpath(your_xpath).map {|e| e.text}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜