
XMLWriter::openMemory 메서드는 메모리 내에 XML 문서를 생성하는 데 사용됩니다. 이 메서드는 XML 문서를 생성할 때 메모리 내에 XML 문서를 저장하므로, XML 문서를 생성한 후 파일로 저장해야 합니다.
XMLWriter::openMemory 메서드를 사용하여 XML 문서를 생성한 후, XMLWriter::output 메서드를 사용하여 XML 문서를 파일로 저장할 수 있습니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$xmlWriter = new XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startElement('root');
$xmlWriter->writeElement('name', 'John Doe');
$xmlWriter->endElement();
$xmlWriter->endDocument();
$xmlString = $xmlWriter->outputMemory();
$file = fopen('example.xml', 'w');
fwrite($file, $xmlString);
fclose($file);
이 예제에서는 XMLWriter::openMemory 메서드를 사용하여 XML 문서를 생성한 후, XMLWriter::outputMemory 메서드를 사용하여 XML 문서를 문자열로 변환한 후, fopen, fwrite, fclose 함수를 사용하여 XML 문서를 파일로 저장합니다.
2025-04-22 04:52