php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32711 CDATA elements are not preserved
Submitted: 2005-04-15 04:34 UTC Modified: 2005-04-18 13:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpspam at talkingspider dot com Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.9 OS: Fedora C2
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:
45 + 25 = ?
Subscribe to this entry?

 
 [2005-04-15 04:34 UTC] phpspam at talkingspider dot com
Description:
------------
Read in an xml file that has CDDATA elements using domxml_open_file and then write it out using DomDocument->dump_file.  The CDATA elements get turned into text elements.




Reproduce code:
---------------
//Read in an xml file that has CDDATA elements using //domxml_open_file and then write it out using //DomDocument->dump_file.  The CDATA elements get turned into text elements.


Expected result:
----------------
There's no justifiable reason why it should convert CDATA elements to text elements. 


Actual result:
--------------
The CDATA elements get turned into text elements.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-16 02:21 UTC] amt@php.net
I don't understand. If you're saying that:

<root><![CDATA[ Hello & Goodbye]></root>

is turned into 

<root>Hello &amp; Goodbye</root>

Then this is not a bug. These are identical in XML and the processor can choose either representation.

It's just like <root></root> vs. <root/>. You cannot control this and no XML parser should care when consuming them.
 [2005-04-17 03:23 UTC] phpspam at talkingspider dot com
No, they are NOT identical. It's called a canonical value. Think back to your computer science education.  

http://www.w3.org/TR/2001/REC-xml-c14n-20010315

The official spec for DOM does specify that CDATA nodes are labelled as such in the DOM.  In other words, in the dom,  CDATA nodes are CDATA nodes and text nodes are text nodes, they are not the same thing.  So, for example, you should be able to crawl the dom and spot CDATA nodes. 

So, either one of two things are still broken: Either your parsing function is deciding to convert CDATA into text nodes, in which case, when the DOM is built, it never has CDATA nodes in it, even though they are present in the input xml.  Or, your output function is deciding to convert all the CDATA nodes in the DOM into text nodes.  In either case, that's a bug.  In perl I can choose to preserve CDATA elements when I output.  In PHP I can't.  

http://www.w3schools.com/dom/dom_cdatasection.asp
 [2005-04-17 04:25 UTC] rrichards@php.net
This has been covered in previous bug reports on why it wont be changed
 [2005-04-17 21:07 UTC] phpspam at talkingspider dot com
Can you give me a link to a previous bug report explaining why this won't be fixed?  (Obviously?)
 [2005-04-18 13:19 UTC] sniper@php.net
Try search for CDATA..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC