in reply to help need when processing xml using perl
use strict; use warnings; my ($xml, $content, @xml); $xml = join '', <DATA>; while ($xml =~ m/(<details>.*?<\/details>)/sg) { $content = $1; next if $content !~ /<address>.+?<\/address>/; push @xml, $content; } $xml = "<specification>\n" . join("\n", map { " $_" } @xml) . "\n</specification>"; print $xml; __DATA__ <specification> <details> <name>johan</name> <address>Langgt 23</address> ---more info--- </details> <details> <name>venu</name> <address>storgatan 27</address> ---more info--- </details> <details> <name>kent</name> <address>nygatan 46</address> ---more info---- </details> <details> <name>johan</name> <branch>ece</branch> ---more info-- </details> </specification>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help need when processing xml using perl
by veerubiji (Sexton) on Nov 29, 2011 at 08:59 UTC | |
by TJPride (Pilgrim) on Nov 29, 2011 at 10:53 UTC |