in reply to Create OO object from XML
You've got quite a few problems here: $class not used in new(); $parser leaps into existence in new(); $parser->parsefile(...); seems to be in totally the wrong place; no connection between new() and startElement(); and others.
Without hacking your code around too much, I'd probably change:
tobless $self; ## now, set up XML::Parser; $parser->parsefile ("/path/to/some/file/$id.xml"); return $self;
bless $self, $class; $self->init(); return $self;
with init() looking something like:
sub init { my $self = shift; my $id = $self->{id}; # Parse the "$id.xml" file here # Get the $property value $self->{property} = $property; return; }
You'd be well advised to put use strict; and use warnings; at the top of your code.
-- Ken
|
|---|