in reply to XML::Twig and oodraw

This might work.

#!/usr/bin/perl use strict; use XML::Twig; my $xml = <<__XML__; <draw:frame draw:id="id2" draw:layer="layout" draw:name="objectName" d +raw:style-name="gr1" draw:text-style-name="P3"> <draw:text-box> <text:p text:style-name="P1"> <text:span text:style-name="T2">objectData</text:span> </text:p> </draw:text-box> </draw:frame> __XML__ my $twig = XML::Twig->new( twig_handlers => { 'draw:frame' => \&handler }, pretty_print => 'indented' ); $twig->parse($xml); sub handler { my ($twig, $elt) = @_; printf "%s\n", $elt->{'att'}->{'draw:name'}; }

Replies are listed 'Best First'.
Re^2: XML::Twig and oodraw
by carcassonne (Pilgrim) on Oct 09, 2009 at 15:13 UTC
    Thanks. I was just about to update my query with the following: ;-)

    sub getDrawInfo { my ($t, $data)= @_; my $name = $data->{'att'}->{'draw:name'}; print "DEBUG name: $name\n"; print "DEBUG " . $data->text . "\n"; }

    Works fine.

      It is cleaner to use the proper method instead of relying on the implementation of the object: $data->att( 'draw:name').

      This way if I ever decide to change the implementation, your code won't break. Not that it is likely at this point, but hey, you never know, there is no promise in the documentation that the attributes be stored in the att field.