Output:#!/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>
---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)
In reply to Re: XML file to split
by NetWallah
in thread XML file to split
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |