DOMDocument::xinclude
(PHP 5, PHP 7)
DOMDocument::xinclude — Substitutes XIncludes in a DOMDocument Object
Description
$options
= 0
] ) : intThis method substitutes » XIncludes in a DOMDocument object.
Note:
Due to libxml2 automatically resolving entities, this method will produce unexpected results if the included XML file have an attached DTD.
Return Values
Returns the number of XIncludes in the document, -1 if some processing failed,
or FALSE
if there were no substitutions.
Examples
Example #1 DOMDocument::xinclude() example
<?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="https://www.gaudry.be/en/php-rf-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();
?>
The above example will output something similar to:
<?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>
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-domdocument.xinclude.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.