473,499 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create an XML file using perl.

crazy4perl
20 New Member
Hi All,

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
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Data::Dumper;
  5. use XML::Dumper;
  6. use TAP3::Tap3edit;
  7.  
  8. $Data::Dumper::Indent=1;
  9. $Data::Dumper::Useqq=1;
  10.  
  11. my $dump = new XML::Dumper;
  12. my $filename=shift;
  13. if ( ! $filename ) {
  14.     die "Usage: $0 filename\n";
  15. }
  16. if($filename =~ m/\.xml$/)
  17. {
  18.     print("$filename is an xml file");
  19.  
  20.     # put code to process xml files.
  21.     my $xml = $filename;
  22.     my $abc = $dump->xml2pl( $xml );
  23.     print Dumper ($abc);
  24. }
  25. else
  26. {
  27.     # code to process tap files.
  28.  
  29.     my  $perl = TAP3::Tap3edit->new();
  30.  
  31.     $perl->decode($filename) || die $perl->error;
  32.     my $struct = $perl->structure;
  33.  
  34.     # printing the file
  35.     print Dumper ($struct);
  36.  
  37.     # write to xml file
  38.     my $file = "tap2xml.xml";
  39.     $dump->pl2xml($struct,$file );
  40. }
  41.  
Feb 25 '08 #1
3 4684
crazy4perl
20 New Member
Actually in the xml file there are some junk characters at line 186.
Feb 25 '08 #2
KevinADC
4,059 Recognized Expert Specialist
if your XML file is in binary encoding you have to convert it to ASCII before parsing it with XML::Dumper. This is covered in the XML::Dumper documentation. I am not sure if that is the problem or not. Also read the XML::Parser documentation because XML::Dumper calls it and the XML::Parser module is whats retuning the error message.
Feb 25 '08 #3
crazy4perl
20 New Member
if your XML file is in binary encoding you have to convert it to ASCII before parsing it with XML::Dumper. This is covered in the XML::Dumper documentation. I am not sure if that is the problem or not. Also read the XML::Parser documentation because XML::Dumper calls it and the XML::Parser module is whats retuning the error message.
Hi Kevin,

Thanks for replying. Actually the xml file contains some junk characters. when I am processing it, after removing those junk character manually, it is processing it sucessfully.

So my question is:- Is there any way to remove (or escape) those junk characters while creating XML file.

Thanks
Raj
Feb 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4430
by: harshan | last post by:
Hi I am trying to read required worksheet from excel file using perl with module spreadsheet::parseexcel and spreadsheet::writeexcel but I am unable to read it, the error I am getting is...
2
15967
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
1
8875
by: Kriston Scott | last post by:
I would like to know how to sort the rows in an Excel file, using Perl.
2
4276
by: prakharv | last post by:
Hi All, I would like to upload a image file from my web page to the server using perl scripting. Please, if any one knows regarding this or has the source code for the same, please help me...
3
3080
by: sainiamit25 | last post by:
Hi, I am trying to set up environment for XML parsing using perl. I downloaded XML::Simple and installed it too. When i try to run my program, it says, you need to install parser. When i try to...
4
3248
by: chandru1985 | last post by:
Hi Guys , Can u help me out in Pel Coding as i'm new to perl . Can any one of them say whether it to print a line in a colored way in the output file using Filehandler .. Codin is :::...
5
4993
by: leierwu | last post by:
1. I have a folder containing several files; 2. Now these files should be added a header with the file name in the first line; How can I complish this using perl script?
3
2573
by: rabtree | last post by:
Hi All, I have to two xls file named test1.xls and test2.xls In test1.xls sheet contain 3 colunm 1.Sr.No 2.Case Name 3.Validation case
1
1768
by: msxi | last post by:
Hi, I have s sed script that removes the following lines from a db dump file. I would like to remove these lines using perl. Could anybody assist? /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.