I have some doubt related to xml. Actually I want to update a file which is in some format. So I am converting that file using Tap3edit perl module in a hash. Now I m trying to create a XML file using this hash so that I can edit that file and convert it back to the same format (might be there are some better way to edit... any suggestions are welcome).
As there are so many xml modules I m not sure which one will be the best n easy to use. I tried with XML-Dumper . But when I m converting it back using xml2pl it is giving me following error:-
not well-formed (invalid token) at line 186, column 40, byte 7090 at C:/Perl/lib/XML/Parser.pm line 187
I believe I have to specify some schema or DTD for xml but dont know how as I m not much familiar with xml. Here is my peice of code
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Data::Dumper;
- use XML::Dumper;
- use TAP3::Tap3edit;
- $Data::Dumper::Indent=1;
- $Data::Dumper::Useqq=1;
- my $dump = new XML::Dumper;
- my $filename=shift;
- if ( ! $filename ) {
- die "Usage: $0 filename\n";
- }
- if($filename =~ m/\.xml$/)
- {
- print("$filename is an xml file");
- # put code to process xml files.
- my $xml = $filename;
- my $abc = $dump->xml2pl( $xml );
- print Dumper ($abc);
- }
- else
- {
- # code to process tap files.
- my $perl = TAP3::Tap3edit->new();
- $perl->decode($filename) || die $perl->error;
- my $struct = $perl->structure;
- # printing the file
- print Dumper ($struct);
- # write to xml file
- my $file = "tap2xml.xml";
- $dump->pl2xml($struct,$file );
- }