473,785 Members | 2,291 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 4707
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
4449
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 subroutine &main::worksheet not found. any help regarding this will be greatly appriciated. Harshan
2
15994
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 script. Now I want to delete a line from a file. Line being the strings I got/saved to/from array of arrays.
1
8912
by: Kriston Scott | last post by:
I would like to know how to sort the rows in an Excel file, using Perl.
2
4302
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 out. Any information on this topic will be appreciated. Thanks And Regards, Prakhar
3
3228
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 install XML::Parser, it says i need to install expact parser. But when i do not how to install and set up that. Can anybody help me know the shortest and quickest way to run my perl script which is ready to parse a xml file. Also i have installed...
4
3271
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 ::: Open(OUTFILE, ">$curDir/file2.out"); print OUTFILE "$result1\n\n"; close(OUTFILE);
5
5014
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
2636
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
1784
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 */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.