2011-08-15 5 views
0

이 스크립트는 원본 데이터로 새 XML 파일을 만들고 업데이트하지 않습니다.PHP 스크립트가 업데이트없이 xml을 저장합니다.

<?php 

$dom = new DOMDocument(); 
$dom->load('communities.xml'); 

$dom->preserveWhiteSpace = false; 
$dom->formatOutput = true; 

// get document element 

$root = $dom->documentElement; 

$name  = $dom->createElement("NAME"); 
$nameText = $dom->createTextNode("Hobbies"); 
$name->appendChild($nameText); 

$community = $dom->createElement('COMMUNITY'); 
$community->appendChild($name); 
$dom->save('communities.xml'); 

$tidy_options = array(
       'input-xml' => true, 
       'output-xml' => true, 
       'indent'  => true, 
       'wrap'   => false, 
     ); 
$tidy = new tidy(); 
$tidy->parseFile('communities.xml', $tidy_options); 
$tidy->cleanRepair(); 
echo $tidy; 

return; 

?> 

파일 형식이 수정되고 파일이 새로운 날짜로 저장되기 때문에 권한이 맞습니다.

+0

정확하게 여기에있는 질문은 무엇입니까? –

답변

1

어떤 DOM 오류 which'll 출력 : 당신이 요소를 생성 한 후

$root->appendChild($name); 
... 
$root->appendChild($community); 
+0

예,'$ root-> appendChild ($ community);가 없습니다. 감사. – user823527

0

파일이 수정되어 새로운 날짜가있을 수 있지만 두 번의 저장 작업을 수행하고 있으며 실제로는 깔끔한 작업 만 수행 중일뿐입니다. 시도 :

if ($dom->save('communites.xml') === FALSE) { 
    die(libxml_get_errors()); 
} 

일부 즉, 문을 추가 누락 된 것 같습니다

0

, 당신은에 추가해야 문서 :

$community = $dom->createElement('COMMUNITY'); 
$root->appendChild($community); 
관련 문제