Строка вырезания синтаксического анализатора XML, содержащая ударение - PullRequest
1 голос
/ 24 декабря 2011

Я пытаюсь разобрать файл XML, но когда в моем файле есть ударение (é, à, ...), синтаксический анализатор php xml обрезает строку.

   function __construct(){
        $this->xml_parser = xml_parser_create("UTF-8"); 
        xml_set_object (  $this->xml_parser, $this );
        xml_set_element_handler($this->xml_parser, "startTagArticle", "endTagArticle"); 
        xml_set_character_data_handler($this->xml_parser, "contentsArticle"); 
        }

Если мой файл содержит следующую строку: cccccékkkkkkéllllllll, он будет отображаться как ékkkkkélllllll в моем веб-браузере, и я не знаю, почему.

<?xml version="1.0" encoding="utf-8"?>
<XML>
        <TITRE>cccccékkkkkkéllllllll</TITRE>
        <RESUME>Ceci est le premieré article de blog et l'aut</RESUME>
        <CONTENT>Ceci l'aut est effectivement mon premier article de blog
        et c'est un test
        </CONTENT>
        <FILE_COMMENTS>com1.xml</FILE_COMMENTS>
        <VISIBLE>true</VISIBLE>
        <TAG>Cool</TAG>
        <TAG>article</TAG>
</XML>

Основная функция разбора:

  function startTagArticle($parser, $data){         switch ($data){             case "RESUME":
                    $this->articleSection = 1;
                    break;          case "CONTENT":
                    $this->articleSection = 2;
                    break;          case "FILE_COMMENTS":
                    $this->articleSection = 3;
                    break;          case "VISIBLE":
                    $this->articleSection = 4;
                        break;          case "TITRE":
                    $this->articleSection = 5;
                        break;          case "TAG":
                    $this->articleSection = 6;
                        break;          default:
                    $this->articleSection = 0;
                        break;      }   }


/** Do not work **/
function contentsArticle($parser, $data){ 
        if ($this->articleSection == 1){
            $this->resumeArticleCourant = $data;
        }
        if ($this->articleSection == 2){
            $this->contentArticleCourrant = $data;
        }
        if ($this->articleSection == 3){
            $this->fichier_comArticleCourant = $data;
            $this->comm = new commentaire();
            $this->comm->init($this->comm_rep.$data);
        }
        if ($this->articleSection == 4){
            $this->visibleArticleCourant =  $data;
        }
        if ($this->articleSection == 5){
            $this->titreArticleCourant = $data;
        }
        if ($this->articleSection == 6){
            array_push($this->tag_array,$data);
        }
    }

Странная вещь, если я использую следующую функцию contentArticle, где я заменил = на. =, Она работает нормально. Символы ударений, кажется, обрезают / останавливают поток XML.

/** work **/
function contentsArticle($parser, $data){ 
        if ($this->articleSection == 1){
            $this->resumeArticleCourant .= $data;
        }
        if ($this->articleSection == 2){
            $this->contentArticleCourrant .= $data;
        }
        if ($this->articleSection == 3){
            $this->fichier_comArticleCourant = $data;
            $this->comm = new commentaire();
            $this->comm->init($this->comm_rep.$data);
        }
        if ($this->articleSection == 4){
            $this->visibleArticleCourant =  $data;
    }
        }
        if ($this->articleSection == 5){
            $this->titreArticleCourant .= $data;
        }
        if ($this->articleSection == 6){
            array_push($this->tag_array,$data);
        }
    } 

1 Ответ

0 голосов
/ 25 декабря 2011

Try;

//add
xml_parser_set_option($xml_parser,XML_OPTION_TARGET_ENCODING, "ISO-8859-1").

//and the encoding is
<?xml version="1.0" encoding="utf-8"?>

Надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...