use strict; my $xml=<<ENDOFXML; <shirt size="14"> ... stuff... </tag> <hat name="red" size="7"> ...more stuff... </hat> <shoe> ...shoe stuff... </shoe> ENDOFXML while($xml=~m/\<(.+?)\>(.+?)\<\/\1\>/sig){ my $tag=lc(strip($1)); my $attribs="?"; my $value=strip($2); print "Tag: $tag\n"; print "\tattributes: $attribs\n"; print "\tvalue: $value\n"; } print "Done\n"; exit; ############### sub strip{ #usage: $str=strip($str); #info: strips off beginning and endings returns, newlines, tabs, a +nd spaces my $str=shift; if(length($str)==0){return;} $str=~s/^[\r\n\s\t]+//s; $str=~s/[\r\n\s\t]+$//s; return $str; }
-------------------------------
Sign up now for a free monthly newsletter service!
http://www.bestgazette.com
In reply to Regular expression - parsing and xml string by slloyd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |