DOM DOMDocument::xinclude

(PHP 5, PHP 7, PHP 8)

DOMDocument::xinclude — DOMDocument 개체에서 XIncludes 대체


설명

public DOMDocument::xinclude(int $options = 0): int|false

이 메소드는 DOMDocument 객체에서 » XIncludes를 대체합니다.

메모: libxml2가 엔티티를 자동으로 확인하기 때문에 포함된 XML 파일에 첨부된 DTD가 있는 경우 이 메소드는 예기치 않은 결과를 생성합니다.


매개변수

options
libxml 매개변수. Libxml 2.6.7부터 사용 가능합니다.

반환 값

문서의 XIncludes 수를 반환하고, 일부 처리가 실패한 경우 -1을 반환하고, 대체가 없는 경우 false를 반환합니다.


Examples

예제 #1 DOMDocument::xinclude() 예제

                  
<?php

$xml = <<<EOD
<?xml version="1.0" ?>
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
 <title>Books of the other guy..</title>
 <para>
  <xi:include href="book.xml">
   <xi:fallback>
    <error>xinclude: book.xml not found</error>
   </xi:fallback>
  </xi:include>
 </para>
</chapter>
EOD;

$dom = new DOMDocument;

// let's have a nice output
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

// load the XML string defined above
$dom->loadXML($xml);

// substitute xincludes
$dom->xinclude();

echo $dom->saveXML();

?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

<?xml version="1.0"?>
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
  <title>Books of the other guy..</title>
  <para>
    <row xml:base="/home/didou/book.xml">
       <entry>The Grapes of Wrath</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>0140186409</entry>
      </row>
    <row xml:base="/home/didou/book.xml">
       <entry>The Pearl</entry>
       <entry>John Steinbeck</entry>
       <entry>en</entry>
       <entry>014017737X</entry>
      </row>
    <row xml:base="/home/didou/book.xml">
       <entry>Samarcande</entry>
       <entry>Amine Maalouf</entry>
       <entry>fr</entry>
       <entry>2253051209</entry>
      </row>
  </para>
</chapter>