Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi Monks! I have the following problem with CGI and XML::Smart. The short description: I get two parameters from GET request and pass them to XML::Smart methods to put them into xml file. The parameters I send are in Russian, so I use UTF-8 encoding. But when I do "cat xml/newfile.xml", all the info in tags is encoded to something weird. Like this:
cat xml/newfile.xml <?xml version="1.0" encoding="UTF-8" ?> <?meta name="GENERATOR" content="XML::Smart/1.78 Perl/5.014002 [linux] +" ?> <quotes> <txt>English text is fine</txt> <play>Really fine </play> <txt dt:dt="binary.base64">0KbQuNGC0LDRgtCwDQoK</txt> <play dt:dt="binary.base64">0J/QvtC/0L7QsdCw0LLQsAo=</play> </quotes>
I really don't know how to handle it. Here's some code of the script which adds this xml info:
#!/usr/bin/perl use strict; use XML::Smart; use CGI; use HTML::Template; use lib ('../'); use MySite; my $q = CGI->new(); my %params = MySite::get_params($q); my $add_quote_success= HTML::Template->new(filename =>'../templates/ad +d_quote_success.tmpl'); my $add_quote_error= HTML::Template->new(filename =>'../templates/add_ +quote_error.tmpl'); if ($ENV{REQUEST_METHOD} ne 'POST') { print "Content-type: text/html\n\n"; print "Stop wgetting this script."; } else { if (($params{txt} eq '') or ($params{play} eq '')) { print $q->header(-charset => 'utf-8'); print $add_quote_error->output; } else { my $XML = XML::Smart->new('../xml/newfile.xml'); my $counter = @{$XML->{quotes}{txt}}; $XML->{quotes}{txt}[$counter] = "$params{txt}\n"; $XML->{quotes}{play}[$counter] = "$params{play}\n"; $XML->save('../xml/newfile.xml'); print $q->header(-charset => 'utf-8'); print $add_quote_success->output; } }

In reply to XML::Smart and UTF-8 by Kyshtynbai

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (11)
    As of 2019-11-14 18:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (80 votes). Check out past polls.

      Notices?