cancel
Showing results for 
Search instead for 
Did you mean: 

Perl programming advice needed: handling XML files?

oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Perl programming advice needed: handling XML files?

Sorry if this is a bit misplaced but stuff in "computers and hardware" doesn't get much attention.
Anyway...
I'm thinking of writing some web-based tools that process datafiles in an XML-ish format.
I've looked through the list of parsers in CPAN and I'm lost. I sort of want something like XML::Structured but without having to install the backend package.
I'm aware that the modules are unlikely to be on ccgi.plus.net but as long as its a pure module or an XSUB it can probably be installed non-root using PREFIX=~ or similar.
4 REPLIES 4
Colin
Grafter
Posts: 1,264
Registered: ‎04-04-2007

Re: Perl programming advice needed: handling XML files?

I usually use XML::Simple if I'm parsing XML in Perl - although it will depend on what you want to use it for.
oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Re: Perl programming advice needed: handling XML files?

Hey thanks for the tip.
Looks like a good choice, I only started looking at Structured because Indigoperl appeared to have it in their package repository. Didn't work though. Much to my suprise CPAN did though.
I'm torn ... I've got XML::Structured installed now, and I like the DTD system it uses, but its stricter than I'd like and I'm finding that "CAL3D" XML isn't "well formed" as it has two root tags, which XML::Structured objects to.  I can work around that by adding tags around the whole document so it thinks the two roots are subtags.
I like the idea of XML::Simple but I don't like the idea of it throwing curve balls like how if a tag only appears once its a pointer to a hash but if it appears more than once it points to an array.
Colin
Grafter
Posts: 1,264
Registered: ‎04-04-2007

Re: Perl programming advice needed: handling XML files?

Anything parsing XML should object to having two root tags IMO Smiley
I can't say I've used XML::Simple that much recently - the last time I actually recall using it for definite was as a quick script when using Tomcat at Uni to update one of it's XML config files with new classes Cheesy
oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Re: Perl programming advice needed: handling XML files?

Yes, I take your point but the problem is I didn't come up with the format.
I guess this is what happens when a designer decides they can just use "XML" without actually being compliant.
Here's what the beginning of the file looks like:
<HEADER MAGIC="XMF" VERSION="910" />
<MESH NUMSUBMESH="1">
    <SUBMESH NUMVERTICES="4" NUMFACES="2" MATERIAL="2" NUMLODSTEPS="0" NUMSPRINGS="0" NUMTEXCOORDS="2">
You're exactly right it wants to interpret that "header" as being the entire document.