in reply to Re: How to remove error: Code point \u0016 is not a valid character in XML
in thread [Solved]:How to remove error: Code point \u0016 is not a valid character in XML

Thanks for all your inputs. @stevieb: I think the problem is at line 50 in the file which I am guessing from the error I see after adding :encoding(UTF-8) in filehandle at line 17 which now looks like open(my $fh, "<:encoding(UTF-8)", "20150626102938.txt")

(Thanks to AnomalousMonk for sugestion)

I am on perl v5.10.1 at present and will see if can get it upgraded but it'll be a while before I can get it done.

@AnomalousMonk: I was trying to do this

perl -pe's/\x08//g' <20150625163139.xml >20150625163139.xml

from the code. And I tried using two different file names as well. I just kept getting same error so just left it there. But if I can get it working, then I'll ensure to use two different files there.

I am sorry for causing confusion about 20150625163139.xml. It is just an existing text file (generated at run time) which I have to use to generate xml. I can change it's extension to .txt though.

I tried adding

:encoding(UTF-8)

in filehandle at line 17 which now looks like

open(my $fh, "<:encoding(UTF-8)", "20150626102938.txt")

Before adding the output of script was:

Code point \u0016 is not a valid character in XML at ./Call_to_snmpwal +k_V_1.pl line 34

After adding the output of script was:

utf8 "\xB8" does not map to Unicode at ./Call_to_snmpwalk_V_1.pl line +35, <$fh> line 50. utf8 "\xF3" does not map to Unicode at ./Call_to_snmpwalk_V_1.pl line +35, <$fh> line 50. Code point \u0016 is not a valid character in XML at ./Call_to_snmpwal +k_V_1.pl line 34

@sundialsvc4: I am sorry for confusion caused by 20150625163139.xml It's just text file with no <?xml version="1.0" encoding="UTF-16" standalone="no"?> at the top I tried adding that tag manually at the top in file 20150625163139.xml just to give it a try but it still gives same error with and without :encoding(UTF-8) added in filehandle

@afoken: Thanks for adding the context link.

Replies are listed 'Best First'.
Re^3: How to remove error: Code point \u0016 is not a valid character in XML
by Perl300 (Friar) on Jun 26, 2015 at 21:35 UTC
    Hi all,

    I got the line in the input file which is causing this error:

    Code point \u0016 is not a valid character in XML at ./Call_to_snmpwalk_V_1.pl line 35

    The line is:

    GI-eSTB-MIB-NPH::eSTBOobNetworkAddress.0 = STRING: ¸^V^Y(^Xó

    I made a few changes so as to print the generated xml in xml file instead of console and can see that the file generations stops at run time at the above line. That generated xml looks like:

    <doc> <GI-eSTB-MIB-NPH> <eSTBOobNetworkAddress> <0>

    Updated code now is:

    #!/usr/bin/perl use strict; use warnings; use XML::Writer; use XML::Simple; use XML::LibXML; use IO::File; my $out = IO::File->new(">output.xml"); my $xml = XML::Writer->new(OUTPUT => $out, DATA_MODE => 1, DATA_INDENT + => 4); $xml->xmlDecl(); $xml->startTag('doc'); my $check_1 = 0; open(my $fh, "<", "20150626161859.txt") or die "Failed to open file: $!\n"; while(<$fh>) { chomp; next if !length; my ($string1, $string2, $subscript_name, $subscript_value) = / ^(.*?):: ([^\s]+) \.([^\s]+)\s+= \s(.*) /x; if ( $check_1 == 0 ) { $xml->startTag($string1); $check_1 += 1; } $xml->startTag($string2); $xml->dataElement($subscript_name => $subscript_value); $xml->endTag(); } $xml->endTag(); $xml->endTag(); $xml->end(); close $fh; $out->close();
    At least I know what exact line/characters are causing trouble now. I trying to find how to avoid this and will update here if I finally get a solution for it.