note 96306 modified in function.domdocument-xinclude by danbrown
| From: | danbrown@php.net | Date: | Fri, 19 Feb 2010 18:20:44 +0000 |
| Subject: | note 96306 modified in function.domdocument-xinclude by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166192@lists.php.net to get a copy of this message | ||
I had to do things a bit differently to use xincludes (also following the example above only
included a part of the XML):
<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>
<site xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="home.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: home.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="services.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: services.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="about.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: about.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="contact.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: contact.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
</site>';
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xml);
$xmlDoc->xinclude();
echo $xmlDoc->saveXML();
?>
--was--
I had to do things a bit differently to use xincludes (also following the example above only
included a part of the XML):
$xml = '<?xml version="1.0" encoding="utf-8"?>
<site xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="home.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: home.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="services.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: services.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="about.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: about.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
<xi:include href="contact.xml#xpointer(/site/*)">
<xi:fallback>
<error>Error: contact.xml not found or invalid!</error>
</xi:fallback>
</xi:include>
</site>';
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xml);
$xmlDoc->xinclude();
echo $xmlDoc->saveXML();
http://php.net/manual/en/function.domdocument-xinclude.php