On Thu, 2008-09-25 at 14:14 +0300, Vyacheslav Karamov wrote:
> Paolo Gianrossi пишет:
> > On Thu, 2008-09-25 at 13:00 +0300, Vyacheslav Karamov wrote:
> >   
> >> Paolo Gianrossi пишет:
> >>     
> >>> On Thu, 2008-09-25 at 12:03 +0300, Vyacheslav Karamov wrote:
> >>>   
> >>>       
> >>>> Hi All!
> >>>>
> >>>> I need to parse XML with XML::Parser::Expat and make XML tree with 
> >>>> Tree::Simple.
> >>>> But I need to store tag value and its attributes. But 
> >>>> Tree::Simple->setNodeValue() accepts single scalar (value itself).
> >>>> How to create something like this?
> >>>>
> >>>> struct
> >>>> {
> >>>>     $value;
> >>>>     %attributes;
> >>>> } $nodeValue;
> >>>>
> >>>> Tree::Simple->setNodeValue( $nodeValue);
> >>>>
> >>>>
> >>>> The pseudo code above  shows what I actually need. But I don't know how 
> >>>> to implement it.
> >>>>     
> >>>>         
> >>> Don't know about xml, but based on your code, it seems like you need a
> >>> reference.
> >>>
> >>> Something like
> >>>
> >>> my $nodeValue = {value=>$value, attributes=>\%attributes};
> >>>
> >>> should do the trick. 
> >>>
> >>> perldoc perlreftut might give insights.
> >>>
> >>> Hope this helps
> >>>
> >>> cheers
> >>> paolino
> >>>    
> >>>
> >>>   
> >>>
> >>>       
> >> but how can I get access to attributes?
> >>
> >> print $nodeValue->{"value"}, " ", "\n" if defined 
> >> $nodeValue->{"value"};  #ok
> >> print $nodeValue->{"attrubutes"}, " ", "\n" if defined 
> >> $nodeValue->{"attrubutes"}; #fail
> >>     
> >
> > watch the typo! 
> >
> > print $nodeValue->{"attributes"}, " ", "\n" if defined
> > $nodeValue->{"attributes"};
> >
> >
> > paolino
> >
> >   
> >>     
> What did you mean?
> Attributes corresponds  XML attributes
> in my particular case
> <child1 acronym_check="1" check_author="1">
> or <child1>
> i.e. some nodes could have some attributes.

you wrote attrubutes. If you meant attributes, with an i, then that
might be the issue. 

Also, print $nodeValue->{attributes} won't give you the attributes, but
some obscure reference pointer. To see inside, 

use Data::Dumper;
print Dumper($nodeValue->{attributes});

to access them, $nodeValue->{attributes}->{attribute_key} should make
it.

cheers
paolino

> 
-- 
Paolo Gianrossi
Softeco Sismat S.p.A. - R&D Division
via De Marini 1, 16149 Genova
Tel: +39 010 6026 332 - Fax: +39 010 6026 350
E-Mail: [EMAIL PROTECTED]




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to