Re: Need help

Chaitanya Yanamadala <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Hai nicholas
 Thank you for you help..
this is doing the needfull
but i think it has one small bug.


for my xml it is not giving the output of the note

if it is given in quotes then it is working though..

Regards
Chaitanya

On Mon, Jun 21, 2010 at 7:08 PM, Nicolas Mendoza <[email protected]>wrote:

> På Mon, 21 Jun 2010 12:05:30 +0200, skrev Chaitanya Yanamadala <
> [email protected]>:
>
>
>  Hai
>>  I have a small query regarding to xml reading and writng..
>>
>> i have an xml like this
>> <a value="5" note=2 >
>> <b><c>hello</c></b>
>> </a>
>>
>> now i need to add a new attribute to node a.
>>
>> can any one help me how to do it..
>>
>> Chaitanya
>>
>
>
> There are many ways to do this, but one is:
>
> use XML::TreePP;
>
> my $tpp = XML::TreePP->new();
>
> my $in_xml =<< 'END_XML'
>
> <a value="5" note=2 >
> <b><c>hello</c></b>
> </a>
> END_XML
> ;
>
> my $tree = $tpp->parse($in_xml);
>
> $tree->{'a'}->{'-new_attribute'} = 'new_value';
>
> print $tpp->write($tree);
>
> $ perl /tmp/lol.pl
> <?xml version="1.0" encoding="UTF-8" ?>
> <a new_attribute="new_value" value="5">
>
> <b>
> <c>hello</c>
> </b>
> </a>
>
>
> To do it "properly" you might want to look into XML::LibXML and use DOM
> methods, but for me XML::TreePP does the trick most of the time ;-)
>
> -- Sendt med Operas revolusjonerende e-postprogram:
> http://www.opera.com/mail/
>

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.