Link to home
Start Free TrialLog in
Avatar of johnsm
johnsm

asked on

Perl and XML::Parser

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.
Avatar of rj2
rj2

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/

Avatar of johnsm

ASKER

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?




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
Avatar of johnsm

ASKER

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.

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".
Avatar of johnsm

ASKER

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.
Avatar of johnsm

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial