XML returning strange characters

1

I manage a code in Php that requests data from the server as a "changelog" from a game server. But in the changelog XML returns strange values. For example, in the words "creation" the result is " creation " or "you" the result is "you! "

Full XML it returns this:

<?xml version="1.0" encoding="Windows-1250" ?>
<SauronGamer>
<Count>2</Count>
    <Content>
        <News>
            <title>[22/04] Preparando tudo para o OpenBETA</title>
            <description>Galera com todos os nosso projetos estamos felizes em anunciar que depois de tanto tempo sim! O OpenBETA será aberto ao público! Como muitos minigames e muita diversăo.</description>
        </News>
        <News>
            <title>[NA] Criamos o servidor SauronServer.</title>
            <description>Foi iniciado o projeto de criação do servidor sauron server de mingames para vocês!</description>
        </News>
    </Content>
</SauronGamer>

The main goal would be for the "changelog" to be in the database and return in json, but I could not make it when I was fetching_row it to add an item in array();

PHP code:

<?php
error_reporting(0);
header("content-type: text/xml");

$comando1 = "SELECT * FROM  'saurongamer_news' ORDER BY  'ID' DESC LIMIT 0,10 ";

mysql_connect('localhost', 'root', 'usbw');
mysql_select_db('test');

$consulta1 = mysql_query($comando1) or die(mysql_error());

if($consulta1 == TRUE){
    line('<?xml version="1.0" encoding="Windows-1250" ?>');
    line('<SauronGamer>');
        line('<Count>' . mysql_num_rows($consulta1) . '</Count>');
            line('<Content>');

                while($row = mysql_fetch_array($consulta1)){
                    line('<News>');
                        line('<title>' . $row[1] . '</title>');
                        line('<description>' . $row[2] . '</description>');
                    line('</News>');
                }

            line('</Content>');
    line('</SauronGamer>');
}

else{

}

function line($text){
    echo $text . "\n";
}
?>
  

I have tried all possible combinations like ISO-5859-1, ISO-5859-2, ISO-5859-15, ANSI, UTF-8, Windows-1250 and the characters remain strange.

And in C # a simple code that reads this:

 private const string UpdateNovidadesServer = "http://localhost:8080/minecraft/novidades.php";

    public Dictionary<string, string> UpdateNovidades()
    {
        var dicionario = new Dictionary<string, string>();


        XmlTextReader xtr = new XmlTextReader(UpdateNovidadesServer);
        xtr.ReadStartElement("SauronGamer");

        xtr.ReadStartElement("Count");
        int size = xtr.ReadContentAsInt();
        xtr.ReadEndElement();

        xtr.ReadStartElement("Content");

        for (int i = 0; i < size; i++)
        {
            xtr.ReadStartElement("News");

            xtr.ReadStartElement("title");
            string k = xtr.ReadContentAsString();
            xtr.ReadEndElement();

            xtr.ReadStartElement("description");
            string v = xtr.ReadContentAsString();
            xtr.ReadEndElement();

            dicionario.Add(k, v);

            xtr.ReadEndElement();

        }

        xtr.ReadEndElement();

        xtr.ReadEndElement();


        return dicionario;
    }
    
asked by anonymous 26.04.2016 / 03:10

1 answer

0

... this is not a good answer, it is another comment of difficult format:

Your XML file is corrupted: it denotes two different mixed encodings:

  • the first paragraph of despription is in UTF8 (probably coming from an original Latin1 = iso_8859-1 = CP1252)
converte( CP1252->UTF8, "texto em CP1252")
  • the second paragraph description was in CP1250 format and was converted to UFT8 as if it were in latin1 = CP1252 ie it was in corrupted format:
converte( CP1252->UTF8, "texto em CP1250")

So your problem is that you have "sources" in different encodings, to be processed with the same conversion process.

    
26.04.2016 / 12:52