?
Solved

Perl and XML::Parser

Posted on 2002-06-18
9
Medium Priority
?
421 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
[X]
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
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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

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.…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 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