Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

Getting Chinese from my Perl script or browser

My Perl script creates xml and outputs it to the browser. However, the code is not working as it should. The funny part is that I got a bunch of chinese letters as output, or maybe the browser interpreted it that way, I don't know. I am using Chrome. Got to wonder if anything of this makes sense?

Adding the letters as a screenshot, they won't display correctly here on the webpage.

Google translate couldn't make much out of it..
Chinese.png
SOLUTION
Avatar of Jax Tan
Jax Tan
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mazdajai
Mazdajai
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

I did it this way:

use XML::Writer;
use CGI;
use CGI::Pretty;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;

my $cgi=new CGI;

sub writeXMLToBrowser {
	my $stuff = shift;
	my $output = "";
	$stuff = "Obsolete" if(!defined($stuff));
	my $writer = XML::Writer->new(
		OUTPUT      => \$output,
		DATA_MODE   => 1,
		DATA_INDENT => 1,
		NEWLINES => 0
	);
	$writer->xmlDecl('UTF-8');
	$writer->startTag('info');
		$writer->startTag('stuff');
		$writer->characters($stuff);
		$writer->endTag('stuff')
	$writer->endTag('info');
	$writer->end();
	print $cgi->header('text/xml'), $output;
}

Open in new window


And that works without any Chinese output to my browser. But I still think those characters were weird, and wonder where they came from. Google translate did translate it from Chinese to English, so the characters must have been Chinese, but the translation made no sense.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

I understand - the code shown above is the code that now is working. I send text to the sub and it outputs it as xml. The sub shown here is a bit revised, so this one only shows two tags nested. The idea is the same as what I use in my code though.

The code that produced the chinese characters was simply a print statement with an xml header, as shown in the thread here above(e.g.  <?xml version="1.0" encoding="UTF-8"?>) and then another print statement with my xml code in one long string (e.g "<tag1><tag2></tag2></tag1>").

Weird stuff that chrome should pick up Chinese letters as a result of that. Do the Chinese letters have some kind of ascii codes? Is it possible that my previously invalid code could output something that could have been interpreted as ascii codes for Chinese by the browser?
Avatar of itnifl

ASKER

I guess there is no more a solution to this then displayed here..