From: William James Date: 2006-02-21T08:03:43+09:00 Subject: Re: How can I search value from xml Artit Satanakulpanich wrote: > How can i search value from xml file such as I want to find from *pubdate *and > return* **biblioentry > *Please give me some source code for further study* > ** > > "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> > > > > Godfrey > Vesey > > Personal Identity: A Philosophical Analysis > > Cornell University Press > > 1977 > class String def xtag(s) scan( %r! < #{s} (?: \s+ ( [^>]* ) )? > ( .*? ) !mx ). map{ |attr, data| h = { } if attr attr.scan( %r! ( \S+ ) = " ( [^"]* ) " !x ){ |k,v| h[k] = v } end [ h, data ] } end end gets(nil).xtag("biblioentry").each { |attr,data| if data.xtag("pubdate")[0][1] > "1984" print attr["id"], data, "\n" end }