Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML file to split
by mirod (Canon) on Oct 09, 2009 at 16:22 UTC | |
|
Re: XML file to split
by ikegami (Patriarch) on Oct 09, 2009 at 16:15 UTC | |
|
Re: XML file to split
by NetWallah (Canon) on Oct 09, 2009 at 17:20 UTC | |
by Anonymous Monk on Oct 10, 2009 at 05:59 UTC | |
by Anonymous Monk on Oct 13, 2009 at 06:12 UTC | |
|
Re: XML file to split
by llancet (Friar) on Oct 10, 2009 at 07:37 UTC |