J
JAG
I have an XML file that looks like this:
<root>
<economist publications="true" >
<name>
<first>John</first>
<last>Doe</last>
</name>
<keywords>
<keyword>Foo</keyword>
<keyword>Bar</keyword>
</keywords>
<title>Indian Chief</title>
</economist>
<economist publications="true" >
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<keywords>
<keyword>More Foo</keyword>
<keyword>More Bar</keyword>
</keywords>
<title>President</title>
</economist>
</root>
But the actual file has about 100 <economist> elements.
I need to write some Perl code to parse this XML file and
write out 100 smaller XML files, each file corresponding to one
<economist> element.
So in my example, I'd write 2 smaller files, one that
looks like this:
<economist publications="true" >
<name>
<first>John</first>
<last>Doe</last>
</name>
<keywords>
<keyword>Foo</keyword>
<keyword>Bar</keyword>
</keywords>
<title>Indian Chief</title>
</economist>
and one that looks like this:
<economist publications="true" >
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<keywords>
<keyword>More Foo</keyword>
<keyword>More Bar</keyword>
</keywords>
<title>President</title>
</economist>
There are some nested elements in the real file, so I think
XML::Simple won't work for this.
Any ideas about how I can do this? I don't need to do any processing
(at least not now) - just reading and writing smaller chunks.
Thanks!
<root>
<economist publications="true" >
<name>
<first>John</first>
<last>Doe</last>
</name>
<keywords>
<keyword>Foo</keyword>
<keyword>Bar</keyword>
</keywords>
<title>Indian Chief</title>
</economist>
<economist publications="true" >
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<keywords>
<keyword>More Foo</keyword>
<keyword>More Bar</keyword>
</keywords>
<title>President</title>
</economist>
</root>
But the actual file has about 100 <economist> elements.
I need to write some Perl code to parse this XML file and
write out 100 smaller XML files, each file corresponding to one
<economist> element.
So in my example, I'd write 2 smaller files, one that
looks like this:
<economist publications="true" >
<name>
<first>John</first>
<last>Doe</last>
</name>
<keywords>
<keyword>Foo</keyword>
<keyword>Bar</keyword>
</keywords>
<title>Indian Chief</title>
</economist>
and one that looks like this:
<economist publications="true" >
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<keywords>
<keyword>More Foo</keyword>
<keyword>More Bar</keyword>
</keywords>
<title>President</title>
</economist>
There are some nested elements in the real file, so I think
XML::Simple won't work for this.
Any ideas about how I can do this? I don't need to do any processing
(at least not now) - just reading and writing smaller chunks.
Thanks!