use strict; use warnings; use autodie; use XML::Twig; use File::Copy; use Encode; use File::Find::Rule; use XML::Twig; binmode STDOUT, ":utf8"; my $srcDCR='test.xml'; my $logend = $srcDCR; my $logfile = $logend . "log"; open LOG, ">$logfile"; my $tmpdcr = $srcDCR.".tmp"; copy($srcDCR,$tmpdcr); open (FILE,'>:encoding(UTF-8)',"$tmpdcr") or die "Failed to open $ +tmpdcr"; my $twig = XML::Twig->new (keep_encoding => 0); $twig->parsefile($srcDCR); my $root = $twig->root; my $littype_parent = $root->first_child('Metadata'); my $littype_value = $littype_parent->first_child_trimmed_text('Descrip +tion'); print LOG $littype_value; $littype_value = 'C1000 マネージ '; print LOG $littype_value; my $littype_child = $littype_parent->first_child('Description'); $littype_child->set_content($littype_value); print LOG 'final value'; print LOG $littype_parent->first_child_trimmed_text('Description'); $twig->print(\*FILE); close(FILE);
test.xml:
<Metadata> <Description>C1000 &#12510;&#12493;&#12540;&#12472;&#12515;&#12540;&#1 +2477;&#12501;&#12488;&#12454;&#12455;&#12450;</Description> </Metadata>
n the xml the value of description is getting set to C1000 マネージ instead of C1000 &#12510;&#12493;&#12540;&#12472; I am new to perl.

In reply to set_content of XML::twig by test1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.