1

I am trying to read an XML file, and output only a select number of fields however I have ran into two issues (which I think are related) which I have utterly failed at googling.

The XML file I am working with contains a lot of non-english characts, äöåéœ etc...

When I run print Dumper($data); I get results like:

Malbec Vi\x{f1}a Domingo F Sarmiento

When I attempt to read through the XML and output specific fields, those hex symbols become questions marks:

Malbec Vi?a Domingo F Sarmiento

Any tips or at least a direction to go to for googling?

Code is as follows:

#!/usr/bin/perl -w
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;


# What file to use?
my $file = "systemet.xml";
# Read in the data
my $data = XMLin($file);
# Let's get some stuff!
foreach my $status (@{$data->{artikel}}) {
print $status->{namn} . "\n";
}

Thanks for any help and sorry if I sound a little ignorant, it's probably because I am.

Stew
  • 11
  • 1

1 Answers1

4

Try this

binmode(STDOUT, ":utf8");

and refer to this thread How can I output UTF-8 from Perl?

Community
  • 1
  • 1
bpgergo
  • 15,669
  • 5
  • 44
  • 68
  • As I said, that did the trick! Now that that works it's on to next problem that crops up. – Stew Aug 25 '11 at 13:33
  • I agree Stew, I did not add it as an answer for you. I did it for the convenience of other SO users stumbling up on this thread searching for a quick solution. Also, to help them further, you should accept this answer. I imagine I'm trying to find a quick solution, I will be more confident if I find my solution as an accepted answer then as a comment. – bpgergo Aug 25 '11 at 13:40