in reply to XML file to split

Perhaps something along the lines of this:
#!/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; print "---File $filename would contain---\n $content\n"; push @names,$filename; } # Now sort and prepare for output @names = sort(@names); print "I found these names:\n@names\n"; __DATA__ <contacts> <entry> <name>File1</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>12345</zip> </entry> <entry> <name>File2</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>678</zip> </entry> <entry> <name>File3</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>910</zip> </entry> </contacts>
Output:
---File File1 would contain--- <entry> <name>File1</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>12345</zip> </entry> ---File File2 would contain--- <entry> <name>File2</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>678</zip> </entry> ---File File3 would contain--- <entry> <name>File3</name> <street>123 Platypus Lane</street> <city>Burgopolis</city> <state>FL</state> <zip>910</zip> </entry> I found these names: File1 File2 File3

     Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)

Replies are listed 'Best First'.
Re^2: XML file to split
by Anonymous Monk on Oct 10, 2009 at 05:59 UTC
    #!/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.
      How to strip out the empty tags and format the XML file. Please tell me