in reply to extract ids
As I just wrote elsewhere, regexps are not a good tool for parsing XML. There may be comments, <!CDATA ... ]> sections, escaped data, newlines and other whitespace at unexpected places, ...
use strict; use XML::Parser; my $parser = new XML::Parser( Handlers => { Start => sub { my ($expat,$tag,%attr) = @_; print $attr{'molecule_idref'}, "\n" if %attr and exists $a +ttr{'molecule_idref'}; } } ); $parser->parse(\*DATA); __DATA__ <root> <foo molecule_idref="123">fgdfg</foo> <bar molecule_idref="456">fgd <foo other="74" molecule_idref="789">fgdfg</foo> fg</bar> some text about how to write things containing molecule_idref="666". <baz molecule_idref="987"/> </root>
Jenda
Enoch was right!
Enjoy the last years of Rome.
|
|---|