Skip to content

Instantly share code, notes, and snippets.

@mikey179
Created October 12, 2011 14:26
Show Gist options
  • Save mikey179/1281354 to your computer and use it in GitHub Desktop.
Save mikey179/1281354 to your computer and use it in GitHub Desktop.
XML file with XIncludes: with example1.xml the second XInclude is not resolved properly. When changing the order as in example2.xml all XIncludes are resolved properly.
<?xml version="1.0" encoding="utf-8"?>
<parts>
<part name="content">
<h1>XML xinclude example</h1>
<div>
<h2>some some blog entry</h2>
<p>blog entry comment</p>
<p>2011-10-12</p>
</div>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='comments']/node())"></xi:include>
</part>
<part name="comments">
<h2>Comments</h2>
<form action="index" method="post">
<ul>
<li class="clearfix">
<div class="left"><label for="AddComment_mail"><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='label_AddComment_mail']/node())"></xi:include>:*</label></div>
<div class="right"><input type="text" name="AddComment_mail" id="AddComment_mail" size="30"></input>
<input type="hidden" value="1" name="AddComment_entryId"/>
</div>
</li>
<li class="clearfix">
<div class="left"><label for="AddComment_content"><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='label_AddComment_content']/node())">
</xi:include>:*</label></div>
<div class="right"><textarea name="AddComment_content" id="AddComment_content" rows="5"></textarea></div>
</li>
<li class="clearfix">
<div class="left"/>
<div class="right"><input class="btn_submit" type="submit" value="Submit" name="AddComment_submit"/></div>
</li>
</ul>
</form>
</part>
<part name="label_AddComment_mail">
Mail
</part>
<part name="label_AddComment_content">
Comment
</part>
</parts>
<?xml version="1.0" encoding="utf-8"?>
<parts>
<part name="comments">
<h2>Comments</h2>
<form action="index" method="post">
<ul>
<li class="clearfix">
<div class="left"><label for="AddComment_mail"><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='label_AddComment_mail']/node())"></xi:include>:*</label></div>
<div class="right"><input type="text" name="AddComment_mail" id="AddComment_mail" size="30"></input>
<input type="hidden" value="1" name="AddComment_entryId"/>
</div>
</li>
<li class="clearfix">
<div class="left"><label for="AddComment_content"><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='label_AddComment_content']/node())">
</xi:include>:*</label></div>
<div class="right"><textarea name="AddComment_content" id="AddComment_content" rows="5"></textarea></div>
</li>
<li class="clearfix">
<div class="left"/>
<div class="right"><input class="btn_submit" type="submit" value="Submit" name="AddComment_submit"/></div>
</li>
</ul>
</form>
</part>
<part name="label_AddComment_mail">
Mail
</part>
<part name="label_AddComment_content">
Comment
</part>
<part name="content">
<h1>XML xinclude example</h1>
<div>
<h2>some some blog entry</h2>
<p>blog entry comment</p>
<p>2011-10-12</p>
</div>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="" xpointer="xpointer(/parts/part[@name='comments']/node())"></xi:include>
</part>
</parts>
<?php
$doc = new DOMDocument();
$doc->load('example1.xml');
$doc->xinclude();
echo $doc->saveXML();
echo "===========================================\n";
$doc = new DOMDocument();
$doc->load('example2.xml');
$doc->xinclude();
echo $doc->saveXML();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment