This is one XML file. How to break this into 3 files which contains filename as <name> tag.<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>
File1.xml, File2.xml,File3.xml will be created.#!/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"; }
In reply to XML file to split by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |