473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How do I read xml file in perl?

Hello All,

I am very new to perl.I am a java person.
I have to read xml file in perl script and use those values in that file.
So can anybody please help me to solve this xml parsing in perl file.

Thankyou in advance.
Aug 28 '07 #1
5 18207
KevinADC
4,059 Expert 2GB
search cpan for xml modules:

cpan: xml modules

XML::Twig and XML::Simple are often sited as being good xml handling modules.
Aug 28 '07 #2
I have searched in google....
I got the following code to read xml file...

Expand|Select|Wrap|Line Numbers
  1. use XML::DOM;
  2. use XML::DOM;
  3.  
  4. my $file = 'letters.xml';
  5. my $parser = XML::DOM::Parser->new();
  6.  
  7. my $doc = $parser->parsefile($file);
  8.  
  9. foreach my $species ($doc->getElementsByTagName('Letter')){
  10.     print $species->getElementsByTagName('Letter')->item(0)->getFirstChild->getNodeValue;
  11. }
  12.  
when I run this file then it is giving some errors.

Can't locate XML/DOM.pm in @INC (@INC contains: /usr/local/lib/perl5/5.6.1/aix /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/aix /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at xml-dom_write.pl line 4.
BEGIN failed--compilation aborted at xml-dom_write.pl line 4.
is it means i need to put the drivers in classpath.But Where do i need to put and what do i need to put.

please help me out
Aug 28 '07 #3
KevinADC
4,059 Expert 2GB
You need to install the module.

How do I install perl modules?


Note: perl 5.6 is very old, you should upgrade to 5.8 if at all possible.
Aug 28 '07 #4
Dear Kevin,

Thanks for your reply.
I am using Unix machine.I am trying to install required modules by following command.

perl -MCPAN -e shell 'install XML::DOM'

thenit is asking so many questions.How do i know hich one need to give.Is there any specific procedure need to follow.

It is giving the following when i run the command.

fmc /opt/fmc> perl -MCPAN -e shell 'install XML::DOM'


/opt/fmc/.cpan/CPAN/MyConfig.pm initialized.


CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes] yes


The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.



I see you already have a directory
/opt/fmc/.cpan
Shall we use it as the general CPAN build and cache directory?

CPAN build and cache directory? [/opt/fmc/.cpan] /opt/fmc/.cpan


If you want, I can keep the source files after a build in the cpan
home directory. If you choose so then future builds will take the
files from there. If you don't want to keep them, answer 0 to the
next question.



How big should the disk cache be for keeping the build directories
with all the intermediate files?

Cache size for build directory (in MB)? [10] 10


By default, each time the CPAN module is started, cache scanning
is performed to keep the cache size in sync. To prevent from this,
disable the cache scanning with 'never'.

Perform cache scanning (atstart or never)? [atstart] atstart


To considerably speed up the initial CPAN shell startup, it is
possible to use Storable to create a cache of metadata. If Storable
is not available, the normal index mechanism will be used.

Cache metadata (yes/no)? [yes] yes


The next option deals with the charset your terminal supports. In
general CPAN is English speaking territory, thus the charset does not
matter much, but some of the aliens out there who upload their
software to CPAN bear names that are outside the ASCII range. If your
terminal supports UTF-8, you say no to the next question, if it
supports ISO-8859-1 (also known as LATIN1) then you say yes, and if it
supports neither nor, your answer does not matter, you will not be
able to read the names of some authors anyway. If you answer no, names
will be output in UTF-8.

Your terminal expects ISO-8859-1 (yes/no)? [yes] yes


The CPAN module can detect when a module that which you are trying to
build depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Please set your
policy to one of the three values.

Policy on building prerequisites (follow, ask or ignore)? [ask] ask


The CPAN module will need a few external programs to work properly.
Please correct me, if I guess the wrong path for a program. Don't
panic if you do not have some of them, just press ENTER for those. To
disable the use of a download program, you can type a space followed
by ENTER.

Where is your gzip program? [/usr/bin/gzip] /usr/bin/gzip
Where is your tar program? [/usr/bin/tar] /usr/bin/tar
Warning: unzip not found in PATH
Where is your unzip program? []
Where is your make program? [/usr/bin/make] /usr/bin/make
Warning: lynx not found in PATH
Where is your lynx program? []
Warning: wget not found in PATH
Where is your wget program? []
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/bin/ftp] /usr/bin/ftp
What is your favorite pager program? [/usr/bin/more] /usr/bin/more
What is your favorite shell? [/usr/bin/ksh]


Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.

If you don't understand this question, just press ENTER.

Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:

POLLUTE=1 increasing backwards compatibility
LIB=~/perl non-root users (please see manual for more hints)

Your choice: []
Parameters for the 'make' command?
Typical frequently used setting:

-j3 dual processor system

Your choice: []
Parameters for the 'make install' command?
Typical frequently used setting:

UNINST=1 to always uninstall potentially conflicting files

Your choice: []


Sometimes you may wish to leave the processes run by CPAN alone
without caring about them. As sometimes the Makefile.PL contains
question you're expected to answer, you can set a timer that will
kill a 'perl Makefile.PL' process after the specified time in seconds.

If you set this value to 0, these processes will wait forever. This is
the default and recommended setting.

Timeout for inactivity during Makefile.PL? [0]


If you're accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.

Your ftp_proxy?
Your http_proxy?
Your no_proxy?
You have no /opt/fmc/.cpan/sources/MIRRORED.BY
I'm trying to fetch one
LWP not available

Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
if you just type
install Bundle::libnet

Issuing "/usr/bin/ftp -n"

ftp: connect to address ::ffff:153.106.5.70: A remote host did not respond within the timeout period.
Trying ::ffff:199.239.233.95...
ftp: connect to address ::ffff:199.239.233.95: A remote host did not respond within the timeout period.
Trying ::ffff:153.106.5.70...
ftp: connect: A remote host did not respond within the timeout period.
Not connected.
Local directory now /opt/fmc/.cpan/sources
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Bad luck... Still failed!
Can't access URL ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY.

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch MIRRORED.BY
CPAN.pm needs at least one URL where it can fetch CPAN files from.

Please enter your CPAN site: [] CPAN.pm needs at least one URL where it can fetch CPAN files from.

Please enter your CPAN site: []
Aug 28 '07 #5
numberwhun
3,509 Expert Mod 2GB
This is your typical CPAN configuration. You only really need to go through this once, unless you decide to change something later. Here are my three suggestions.

1. For this line: "Policy on building prerequisites (follow, ask or ignore)? [ask] "

I always choose "follow". That way, CPAN automatically downloads, builds and installs any prerequisites to the module(s) that I am installing.

2. Make sure you install all of the programs it is looking for. In other words, take this list:

Where is your gzip program? [/usr/bin/gzip] /usr/bin/gzip
Where is your tar program? [/usr/bin/tar] /usr/bin/tar
Warning: unzip not found in PATH
Where is your unzip program? []
Where is your make program? [/usr/bin/make] /usr/bin/make
Warning: lynx not found in PATH
Where is your lynx program? []
Warning: wget not found in PATH
Where is your wget program? []
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/bin/ftp] /usr/bin/ftp
What is your favorite pager program? [/usr/bin/more] /usr/bin/more
What is your favorite shell? [/usr/bin/ksh]


and make sure that any program not listed is installed before re-running it.

3. After these questions, you will be prompted to select the sites you want to include in your search list (URL's). you would list them by using the number of the sites, separated by a space. I include 2 through 56 ( I think that's the highest one), only I do them in reverse order: ie: 56 55 54 53 52 51 50 ........
until they are all listed. Sure, this is overkill, but if I am looking for a module listed on cpan and its only on one of the mirrors (for example), then I will find it eventually. The reason I list them in reverse order is because the cpan urls are at the end (in the 50's) and seem to respond all the time.

I hope this helped!

Regards,

Jeff
Aug 28 '07 #6

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

Similar topics

3
by: Berk Birand | last post by:
Hi, I am new to Perl (as a matter of fact, I started learning it a couple of days ago; I have some previous programming experience though). When looking for the ideal languages to use for a...
3
by: NNTP | last post by:
I'd lile to read the following file and output everything from 'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of "----------------------------------------" can perl do that?...
1
by: Rob | last post by:
Hi, Sorry if this has been asked before(I searched, but didn't see anything). I need to read a tab delimted file into an array with ASP. Should be easy enough, I know it is in Perl and PHP. Can...
0
by: TRB_NV | last post by:
I'm on a new hosted server platform which doesn't support PERL, so I'm converting some of my old code so it'll run as ASP. I have a routine I wrote in 1998 where I have a standard template Word...
5
by: Radium | last post by:
Hi, what i want is something similar to th simple-xml extension of php, but for html. I have to analyze and read in certain tags from a html file in a comfortable manner. Is there a php...
1
by: bhavanirayala | last post by:
Hi, I am new to perl.Basically I am from java.Now I am getting error while i reading the configuration parameters in perl. #!/usr/bin/perl use Config::Properties; # reading... open...
1
by: bpejman | last post by:
Hi Everyone, I've been reading and searching the web for days trying to figure out how exactly you can access and read a Perl array or hash from within JavaScript. I've been reading that JSON is...
1
by: sandy2481 | last post by:
Hi Friends, I'm a beginner in perl. Can anyone please provide me with a perl code to read a HTML file and write into excel file. Regards, Sandy
15
by: senthilkumars | last post by:
i am running my perl script as "perl script.pl /root/sample/shadow .htpasswd" now i need to pass these inputs in separate file and read from that file. for eg content of file may be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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,...
0
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...

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.