
XMLWriter::openMemory를 사용하여 XML 문서를 메모리에 저장하는 방법은 다음과 같습니다.
1. XMLWriter 클래스를 생성하고 openMemory 메서드를 호출하여 메모리에 XML 문서를 저장할 수 있는 객체를 생성합니다.
2. XML 문서를 작성하기 위해 startDocument, startElement, addElement, addAttribute, text, endElement, endDocument 메서드를 호출하여 XML 문서를 생성합니다.
3. XML 문서를 메모리에 저장하기 위해 close 메서드를 호출합니다.
예를 들어, 다음과 같이 XMLWriter::openMemory를 사용하여 XML 문서를 메모리에 저장하는 방법을 설명할 수 있습니다.
#hostingforum.kr
php
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('root');
$xml->startElement('name');
$xml->text('John Doe');
$xml->endElement();
$xml->startElement('age');
$xml->text('30');
$xml->endElement();
$xml->endElement();
$xml->endDocument();
$xml->close();
$xmlString = $xml->outputMemory();
print($xmlString);
이 예제에서는 XMLWriter::openMemory를 사용하여 XML 문서를 메모리에 저장하고, XML 문서를 출력하는 방법을 보여줍니다.
2025-08-02 23:21