in reply to Re: XML::Smart how to prevent encoding <body> tag
in thread XML::Smart how to prevent encoding <body> tag

sample XML

<actions> <emailNotification> <body>Good day, This email is to inform you we did not receive bla bla bla bla Thank you. bla bla bla bla</body> <cc>x@y.com, z@y.com</cc>

code sample

{ my $isconditional; my $otherwise; for (my $i=0; $i < 1000; $i++) { last if ! exists ($XML->{$type}{actions}{emailNotification +}[$i]{body}); my $body = $XML->{$type}{actions}{emailNotification}[$i]{ +body}->content(); $XML->{$type}{actions}{emailNotification}[$i]{body} = $bod +y; print "DEBUG7 $body\n"; } }

Replies are listed 'Best First'.
Re^3: XML::Smart how to prevent encoding <body> tag
by marto (Cardinal) on Aug 21, 2025 at 11:51 UTC

    Not a decent code or data sample, previously. Fixing the XML and running something like your code (neither the XML you posted nor the code cater for $type), I don't see the issue you have reported:

    XML:

    <actions> <emailNotification> <body> Good day, This email is to inform you we did not receive bla bla bla bla Thank you. bla bla bla bla </body> <cc>x@y.com, z@y.com</cc> </emailNotification> </actions>

    code:

    #!/usr/bin/perl use strict; use warnings; use feature 'say'; use local::lib; use XML::Smart; my $XML = XML::Smart->new('junk.xml'); my $isconditional; my $otherwise; for (my $i=0; $i < 1000; $i++){ last if ! exists ($XML->{actions}{emailNotification}[$i]{body}); my $body = $XML->{actions}{emailNotification}[$i]{body}->content( +); $XML->{actions}{emailNotification}[$i]{body} = $body; say '$body: ' . $body; say 'xml body: ' . $XML->{actions}{emailNotification}[$i]{body}; say $XML->data; }

    Output:

    $body: Good day, This email is to inform you we did not receive bla bla bla bla Thank you. bla bla bla bla xml body: Good day, This email is to inform you we did not receive bla bla bla bla Thank you. bla bla bla bla <?xml version="1.0" encoding="UTF-8" ?> <?meta name="GENERATOR" content="XML::Smart/1.78 Perl/5.042000 [linux] +" ?> <actions> <emailNotification> <body> Good day, This email is to inform you we did not receive bla bla bla bla Thank you. bla bla bla bla </body> <cc>x@y.com, z@y.com</cc> </emailNotification> </actions> 1