php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16420 new_child not working properly
Submitted: 2002-04-04 03:50 UTC Modified: 2002-04-18 01:43 UTC
From: miroslav dot spanel at cad-programs dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.1.2 OS: Windows 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: miroslav dot spanel at cad-programs dot com
New email:
PHP Version: OS:

 

 [2002-04-04 03:50 UTC] miroslav dot spanel at cad-programs dot com
Description of bug:
Placing amperstand '&' in 'content' parameter of 'new_child' method produce trim of content at '&' position.

How to reproduce bug:

<?
$doc = new_xmldoc("1.0");
$root = $doc->add_root('root');
$chld = $root->new_child('element','element&value');
$chld->set_attribute('attr','attribute&value');
echo $doc->dumpmem();
?>

Output will be:

<?xml version="1.0"?>
<root>
  <element attr="attribute&amp;value">element</element>
</root>

Element has only 'element' value instead of 'element&amp;value'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-04 04:01 UTC] miroslav dot spanel at cad-programs dot com
For now I'am using ereg_replace('[&][^amp;]','&amp;',$value) to correct problem.
 [2002-04-16 20:18 UTC] s dot li at gmx dot de
It is the responsibility of the developer to use valid XML when assigning content to a new code. 'element&value' is not valid XML. So in my opinion this is not a bug but a developer shooting himself in the foot :)
 [2002-04-18 01:43 UTC] steinm@php.net
This bug has been fixed in CVS.

The latest cvs version provides better DOM compliance and
has a function DomNode->create_text_node() which even
accepts a '&'.

The following works just fine:
<?php
$doc = domxml_new_doc("1.0");
$root = $doc->create_element("HTML");
$root = $doc->append_child($root);
$head = $doc->create_element("HEAD");
$head = $root->append_child($head);
$title = $doc->create_element("TITLE");
$title = $head->append_child($title);
$text = $doc->create_text_node("This is & the title");
$text = $title->append_child($text);
$body = $doc->create_element("BODY");
$body = $root->append_child($body);
$bodytext1 = $doc->create_text_node("The text of the body");
$bodytext2 = $doc->create_text_node("Some more text of the body");
$bodytext1 = $body->append_child($bodytext1);
$bodytext2 = $body->append_child($bodytext2);

echo "<PRE>";
echo htmlentities($doc->dump_mem(true));
echo "</PRE>";


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 17:01:34 2024 UTC