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
Web BrowsersPerlWeb Development

Avatar of undefined
Last Comment
itnifl
SOLUTION
Avatar of Jax Tan
Jax Tan
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Mazdajai
Mazdajai
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of itnifl
itnifl
Flag of Norway image

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
Avatar of Jax Tan
Jax Tan
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of itnifl
itnifl
Flag of Norway image

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
itnifl
Flag of Norway image

ASKER

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

Web development includes all aspects of presenting content on intranets and the Internet, including delivery development, protocols, languages and standards, server software, browser clients, databases and multimedia generation.

78K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo