File.xml
This is one XML file.Code:<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>
How to break this into 3 files which contains filename as <name> tag.
File1.xml, File2.xml,File3.xml will be created.Code:#!/usr/bin/perl use XML::XPath; my $file = 'file.xml'; my $xp = XML::XPath->new(filename=>$file); my $nodeset = $xp->find('//name'); my @names; # Where we'll put our results if (my @nodelist = $nodeset->get_nodelist) { @names = map($_->string_value, @nodelist); # Now sort and prepare for output @names = sort(@names); local $" = "\n"; print "I found these names:\n@names\n"; }




Bookmarks