[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Perl and XML::Parser

Posted on 2002-06-18
Medium Priority
Last Modified: 2013-11-19
I didn't know whether to put this question here or in the XML section, but I figured only Perl programmers would know the answer to this question.

I am familiar with Perl (I have been using it for a couple of years) but I am just trying to learn XML and use it in conjunction with Perl. I have been browsing around looking for information and it seems like the best way to go is to use the XML::parser module.

Is anyone familiar with this module and how would I use it? What's the syntax for extracting data out of and putting data into an XML type data file?

Thanks for any info.

I am using perl for Win32 so I can't utilize stuff like man pages.
Question by:johnsm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 10

Expert Comment

ID: 7090191
XML::Parser is event based, you define event handlers to the events you are interested in.
You use XML::Parser to read XML.
You can write XML with regular print statements.

Here is a link to a tutorial


Author Comment

ID: 7090485
If I want to use XML to store data and I want to add and attribute or something to an element, do I have to read i the document and write it back with my additions, just as if it were a text document?

I am trying to manipulate large amounts of data without a lot of overhead. I don't want to use the tree method because I think I will run out of memory and thr process will take too long. It seems like I could use the streaming method, but that doesn't seem too different than just reading in a text file line by line and parsing out what is between the tags and putting it in a hash.

I can do that now. I don't understand what advantages the XML format offers.

Am I missing something here?

LVL 10

Expert Comment

ID: 7090663
As far as I know, yes.

The advantages of the XML format includes that
-XML is self describing
-XML is extensible
-you can validate if it adheres to a specific format or not with a DTD or schema
-XML allows professions (like music, chemistry, math) to define their own, domain-specific markup language
-you can  define tree structures, ideal for structured data
-you can define how the XML should be viewed (with XSL)
-XML is non-proprietary and interchangable between applications
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 7090715
But that doesn't address my main concern of being able to insert data into a large XML formatted file without having to read the file in, insert the data, and then rewrite the file back just as if it were a text document.

I'm doing that already. I'm trying to find out what XML would offer me in the way of speed and ease of use. As far as I can see, XML will actually slow down my process and take more overhead in the way of memory because of the way it stores data.

To me, XML looks like an updated version of an .ini file with some new bells and whistles modified for the web.

Thanks for your input.

LVL 10

Expert Comment

ID: 7090760
XML is very useful, but XML is not the answer to everything. If your data is simple, and you are the only one who need to read and write it, a plain tab-separated text file is both faster and easier to read and write.

You need to have the data in a database if you don't want to write the whole file back to disk.

Many people will disagree with you that XML is an "updated ini file".

Author Comment

ID: 7090883
I'm sure they will. And although it was a slight exaggeration, a text file is a text file, anyway you look at it. :\


Author Comment

ID: 7092805
Thanks for the input but I have decided not to use XML as it will not suit my purpose. I have decided to use mySQL instead.

Accepted Solution

SpideyMod earned 0 total points
ID: 8166066
Administrative Action - PAQ'd and points NOT refunded.

Community Support Moderator @Experts Exchange

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question