in reply to Re: XML file to split
in thread XML file to split

#!/usr/bin/perl use XML::XPath; my $xp = XML::XPath->new(xml=> join '',<DATA>); my @names; # Where we'll put our results for my $entry ( $xp->findnodes('//entry') ) { my $filename = $entry->findvalue("./name"); my $content = $entry->toString; $content=~ s/[\cA-\cZ]//g; $content=~ s/\^[A-Z]//g; print "---File $filename would contain---\n $content\n"; } __DATA__ <contacts> <entry>^M <name>File1</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state></state> <zip>12345</zip> </entry> <entry> <name>File2</name> <street>123 Platypus Lane</street> <city></city> <state>FL</state> <zip>678</zip> </entry> <entry> <name>File3</name> <street></street> <city>Burgopolis</city> <state>FL</state> <zip>910 </zip> </entry> </contacts>
How to format the XML file and strip out the empty tags. The tags are not printed in the separate lines.

Replies are listed 'Best First'.
Re^3: XML file to split
by Anonymous Monk on Oct 13, 2009 at 06:12 UTC
    How to strip out the empty tags and format the XML file. Please tell me