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

That module has not been update in over 10 years and has issues, are you married to this or open to alternatives? Can you update your post with an example of the XML you're working with and explain some of the manipulations you need to perform?

  • Comment on Re: XML::Smart how to prevent encoding <body> tag

Replies are listed 'Best First'.
Re^2: XML::Smart how to prevent encoding <body> tag
by zatlas1 (Acolyte) on Aug 20, 2025 at 16:51 UTC

    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"; } }

      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