php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32998 formatOutput breaks cdata section nodes
Submitted: 2005-05-10 14:37 UTC Modified: 2005-05-10 21:00 UTC
From: daine dot mamacos at complinet dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.3 OS: Linux 2.4.21-4.ELsmp
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: daine dot mamacos at complinet dot com
New email:
PHP Version: OS:

 

 [2005-05-10 14:37 UTC] daine dot mamacos at complinet dot com
Description:
------------
If you create an element on a DOMDocument, and then append a CDATA section to the node, if formatOutput is enabled, it makes the node put a return caridge before and after the CDATA section. IE: 
        <key_0>
<![CDATA[BLAHBLAH]]>
        </key_0>

This is problematic, as when you fetch the data from the node, it carries the return caridges with it. The only way of solving this currently (that I know of) is to not use formattput on the DOMDocument.


Reproduce code:
---------------
<?php
   $dom = new DOMDocument("1.0");
   $dom->formatOutput = true;
   $node = $dom->createElement("node");
   $cdata = $dom->createCDATASection("BLAH BLAH BLAH");
   $dom->appendChild($node);
   $node->appendChild($cdata);
   $dom2 = DOMDocument::loadXML($dom->saveXML());
   $rootNode = $dom2->documentElement;
   $text = $rootNode->textContent;
   print("'$text'");
   $packData = @unpack("H*", $text);
   print_r($packData);
?>

Expected result:
----------------
'BLAH BLAH BLAH'Array
(
    [1] => 424c414820424c414820424c4148
)


Actual result:
--------------
'
BLAH BLAH BLAH
'Array
(
    [1] => 0a424c414820424c414820424c41480a
)
//you can see the 0A after the ' and before the closing '

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-10 21:00 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.

you told it to insert those, so dont do that or grab the textContent of CData node
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 12:01:29 2024 UTC