php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23710 Handling of XML entites in set_content() is inconsistent
Submitted: 2003-05-20 04:05 UTC Modified: 2003-05-20 11:27 UTC
From: flying at dom dot natm dot ru Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.2RC3 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 + 16 = ?
Subscribe to this entry?

 
 [2003-05-20 04:05 UTC] flying at dom dot natm dot ru
set_content() handles XML entities differently, depending on context. Take a look at following example:

<?php
$xml = domxml_new_doc('1.0');
$root = $xml->append_child($xml->create_element('root'));
$root->set_content('&#160;');
$root->set_content('&#160;');
echo $xml->dumpmem();
?>

It produces following document:

<?xml version="1.0"?>
<root>&#160;&amp;#160;</root>

 Note, that first entity was determined as entity, but second - as plain text, and hence quoted. Problem is in php_domxml.c, function domxml_node_set_content(), around line 2734 (as for version) 1.218.2.23:

if (nodep->children) {
	xmlNodeAddContentLen(nodep, content, content_len);
} else {
	xmlNodeSetContentLen(nodep, content, content_len);
}

 If you'll take a look into source of these functions in libxml (file tree.c) - you will see, that xmlNodeSetContentLen() parses given content for entities, while xmlNodeAddContentLen() - not. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-20 11:27 UTC] chregu@php.net
set_content is buggy as hell, if you use it twice...

my advice. use it only once or use the proper DOM methods (create_text_node and append_child).

I won't fix it, since domxml support will be phased out in PHP5 and we're currently focusing on a new, much better dom-and-xml-in-general extension.

chregu
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC