라이브러리

[PHP] DOMImplementation::createDocument - 지정된 유형의 DOMDocument 객체를 해당 문서 요소와 함께 생성합니다.




DOMImplementation::createDocument

PHP의 DOMImplementation::createDocument 메소드는 새로운 문서를 생성하는 데 사용됩니다. 이 메소드는 DOMDocument 객체를 반환하며, 이 객체는 새로 생성된 문서를 나타냅니다.

createDocument 메소드의 매개변수


createDocument 메소드는 3개의 매개변수를 받습니다.

- namespaceURI: 문서의 네임스페이스 URI입니다.
- qualifiedName: 문서의 이름입니다.
- doctype: 문서의 DOCTYPE입니다.

예제


다음 예제는 createDocument 메소드를 사용하여 새로운 문서를 생성하는 방법을 보여줍니다.

#hostingforum.kr
php

// DOMImplementation 객체를 생성합니다.

$impl = new DOMImplementation();



// namespaceURI, qualifiedName, doctype를 지정합니다.

$namespaceURI = 'http://www.example.com';

$qualifiedName = 'example';

$doctype = new DOMDocumentType('document', $namespaceURI, $qualifiedName);



// createDocument 메소드를 호출하여 새로운 문서를 생성합니다.

$doc = $impl->createDocument($namespaceURI, $qualifiedName, $doctype);



// 문서의 루트 요소를 생성합니다.

$root = $doc->createElement('root');

$doc->appendChild($root);



// 루트 요소에 텍스트 노드를 추가합니다.

$text = $doc->createTextNode('Hello, World!');

$root->appendChild($text);



// 문서를 출력합니다.

echo $doc->saveXML();



이 예제에서는 createDocument 메소드를 사용하여 새로운 문서를 생성하고, 루트 요소를 생성하고, 텍스트 노드를 추가합니다. 생성된 문서를 saveXML 메소드를 사용하여 출력합니다.

결과


#hostingforum.kr
xml

<?xml version="1.0"?>



  Hello, World!





이 예제는 createDocument 메소드를 사용하여 새로운 문서를 생성하는 방법을 보여줍니다. 이 방법은 DOMDocument 객체를 생성하고, namespaceURI, qualifiedName, doctype를 지정하고, createDocument 메소드를 호출하여 새로운 문서를 생성하는 방법입니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 613 페이지

검색

게시물 검색