I'm using SimpleXML and xpath to read elements from an external UTF-8 XHTML document. I then iteratively echo the output of SimpleXML's asXML() function executed upon each element returned from an xpath selector. But the XML carriage return entity is annoyingly inserted after every line of my code. There aren't any extra characters in the XHTML document. What is causing this? It seems to be the way I'm iterating through each array element returned from xpath. I don't get the entities when I'm just outputting one element directly from SimpleXML's asXML() (without using xpath).
<?php
$content = new DOMDocument();
$content->loadHTMLFile(CONTENT.html);
$story = simplexml_import_dom($content->getElementById('story'));
$topics = $story->xpath('div[@class="topic"]');
foreach ($topics as $topic) {
$topicContents = $topic->xpath('div/child::node()'); // Array of elements within 'content'.
foreach ($topicContents as $contentElement) {
echo $contentElement->asXML();
}
}
?>
Excerpt from outputted XHTML code with auto-generated XML carriage returns:
<div class="content">
<p>Lorem ipsum dolor sit amet</p>
<h2>Lorem ipsum</h2>
<p>Lorem ipsum dolor sit amet</p>
<ul>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>