xml을 사용하는 데 문제가 있습니다. 나는이 질문이 comon 인 것을 안다. 그러나 내가 발견했던 대답은 나의 문제를 해결하지 않았다. 문제는 php domdocument를 사용하여 é 또는 ä 또는 다른 특수 문자를 xml 파일에 추가하면 é을 xE9로, ä를 xE4로 저장한다는 것입니다. 나는 이것이 괜찮은지 모르지만 출력을 보여주고 싶을 때이 장소에 물음표를 보여줍니다. 나는 많이 시도했다. PHP domdocument의 de xml 헤더에서 인코딩을 제거하고 추가하는 것과 같습니다. 나는 또한 file_get_contents를 사용하고 php utf-8_decode를 사용하여 XML을 얻으려고 시도했다. 나는 iso를 사용하여 시도했지만 아무 것도 내 문제를 해결하지 못했습니다. 대신 PHP xml 파싱 오류가 발생했습니다. 나는 틀린 일을해야한다. 그러나 무엇? 그게 내 질문과 어떻게이 문제를 해결할 수 있습니다. 내 xml 파일은 다음과 같습니다. xE9 및 xE4의 배경이 검은 색입니다. xml에서 PHP utf-8 디코드가 물음표를 반환합니다.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row id="1">
<question>blah</question>
<answer>blah</answer>
</row>
<row id="2">
<question>xE9</question>
<answer>xE4</answer>
</row>
</root>
내 PHP의 XML 클래스 이것이 내가 spcial 문자를 추가 할 때까지
//creates new xml row and saves it in xml file
function addNewRow($question, $answer) {
$nextAttr = $this->getNextRowId();
$parentNode = $this->xmlDoc->documentElement;
$rowNode = $this->xmlDoc->createElement('row');
$rowNode = $parentNode->appendChild($rowNode);
$rowNode->setAttribute('id', $nextAttr);
$q = $this->xmlDoc->createElement('question');
$q = $rowNode->appendChild($q);
$qText = $this->xmlDoc->createTextNode($question);
$qText = $q->appendChild($qText);
$a = $this->xmlDoc->createElement('answer');
$a = $rowNode->appendChild($a);
$aText = $this->xmlDoc->createTextNode($answer);
$aText = $a->appendChild($aText);
$this->xmlDoc->save($this->file);
}
모든 것이 잘 작동하는 새로 추가 행 함수에게 있습니다
function __construct($filePath) {
$this->file = $filePath;
$this->label = array('Vraag', 'Antwoord');
$xmlStr = file_get_contents($filePath);
$xmlStr = utf8_decode($xmlStr);
$this->xmlDoc = new DOMDocument('1.0', 'UTF-8');
$this->xmlDoc->preserveWhiteSpace = false;
$this->xmlDoc->formatOutput = true;
//$this->xmlDoc->load($filePath);
$this->xmlDoc->loadXML($xmlStr);
}
의 일부. 그것들은 questionmarks로 표시됩니다.
당신은 특수 문자를 참조 아직 XML 샘플은이 없습니다 : W3C는 당신이 지금 읽고 시사 주제에 대한 몇 가지 유용한 자료를 수집하고있다. ** 그것이 xE9로, ä를 xFC **로 저장한다는 것은 무엇을 의미합니까? PHP 코드는 XML을 DOMDocument 객체로로드하는 것을 보여줍니다. –
xml 예제는 xml 구조의 예제 일뿐입니다. 위에서 설명한대로 파일에 é 및 ä를 추가하면 xE9 및 xFC가 xml 파일에 저장됩니다.이것은 내 수업에 php 함수가있는 html 입력 필드에 의해 수행됩니다. – Zeebats
실제 예제가 없으면 어떻게 도움을받을 것으로 예상합니까? –