Solved

Perl and XML::Parser

Posted on 2002-06-18
9
408 Views
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.
0
Comment
Question by:johnsm
  • 4
  • 3
9 Comments
 
LVL 10

Expert Comment

by:rj2
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
http://www-106.ibm.com/developerworks/library/xml-perl/

0
 
LVL 1

Author Comment

by:johnsm
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?




0
 
LVL 10

Expert Comment

by:rj2
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
0
 
LVL 1

Author Comment

by:johnsm
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.

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 10

Expert Comment

by:rj2
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".
0
 
LVL 1

Author Comment

by:johnsm
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. :\

Thanks.
0
 
LVL 1

Author Comment

by:johnsm
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.
0
 

Accepted Solution

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

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now