Solved

Perl and XML::Parser

Posted on 2002-06-18
9
412 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 196
WCAG audit tools 1 81
Coldfusion- Create and save form elements in Database 7 72
Make Line Items Look Good Over Mobile 2 54
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.…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

785 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