php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34917 saveXML(documentFragment) produces an "empty" <> tag
Submitted: 2005-10-19 15:51 UTC Modified: 2005-10-19 16:32 UTC
From: bart at mediawave dot nl Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.5 OS: Fedora Core 4
Private report: No CVE-ID: None
 [2005-10-19 15:51 UTC] bart at mediawave dot nl
Description:
------------
When using saveXML(node) with a documentFragment an "empty tag" like <> is appended at the beginning of the string. Strangely this occurs with XHTML doctypes but not with XML documents without a doctype. I haven't tested it with other doctypes. It looks like it tries to output the documentfragment as a tag.

Reproduce code:
---------------
<?php 

$xml = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" []> 
<div>
<h1>The quick brown fox jumps over the lazy dog</h1>
<p>And he also jumped over a cow </p>
</div> ';

$doc = new DOMDocument();
$doc->loadXML($xml);

$div = $doc->getElementsByTagName('div')->item(0);

$frag = $doc->createDocumentFragment();

while ($childNode = $div->firstChild) {
	$frag->appendChild($childNode);
}

echo $doc->saveXML($frag);

?>

Expected result:
----------------
The quick brown fox jumps over the lazy dog

And he also jumped over a cow 

Actual result:
--------------
<>

The quick brown fox jumps over the lazy dog

And he also jumped over a cow 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-19 16:08 UTC] rrichards@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

libxml issue. handling it there.
 [2005-10-19 16:32 UTC] bart at mediawave dot nl
Here's a simple workaround for the time being:

<?php 

foreach ($frag->childNodes as $childNode)
	echo $doc->saveXML($childNode);

?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 12:01:30 2024 UTC