php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31779 XML_CDATA_SECTION_NODE is returned as XML_TEXT_NODE
Submitted: 2005-01-31 16:06 UTC Modified: 2005-02-08 23:19 UTC
Votes:4
Avg. Score:4.0 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: galg at sphera dot com Assigned: rrichards (profile)
Status: Wont fix Package: DOM XML related
PHP Version: 4.3.10 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: galg at sphera dot com
New email:
PHP Version: OS:

 

 [2005-01-31 16:06 UTC] galg at sphera dot com
Description:
------------
When I've used the following code on php 4.3.8:
The <![CDATA[ ]> section was returned as XML_CDATA_SECTION_NODE (value 4).

When i am running the same code on 4.3.10 its returned as XML_TEXT_NODE (value 3).








Reproduce code:
---------------
<?php
$sXML = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<XML_DOC>
        <![CDATA[ something inside the CDATA.  ]]>
</XML_DOC>
XML;

print_r(domxml_xmltree($sXML));
?>

Expected result:
----------------
php 4.3.8 response:
=======================
domdocument Object
(
    [name] => #document
    [url] =>
    [version] => 1.0
    [encoding] => UTF-8
    [standalone] => -1
    [type] => 9
    [compression] => -1
    [charset] => 1
    [0] => 4
    [1] => 138008952
    [children] => Array
        (
            [0] => domelement Object
                (
                    [type] => 1
                    [tagname] => XML_DOC
                    [0] => 5
                    [1] => 138009088
                    [children] => Array
                        (
                            [0] => domtext Object
                                (
                                    [type] => 3
                                    [name] => #text
                                    [content] =>

                                    [0] => 6
                                    [1] => 138009160
                                )

                            [1] => domcdata Object
                                (
                                    [type] => 4
                                    [content] =>  something inside the CDATA.
                                    [0] => 7
                                    [1] => 138009320
                                )

                            [2] => domtext Object
                                (
                                    [type] => 3
                                    [name] => #text
                                    [content] =>

                                    [0] => 8
                                    [1] => 138009416
                                )

                        )

                )

        )

)

Actual result:
--------------
php 4.3.10 response:
===========================
domdocument Object
(
    [name] => #document
    [url] =>
    [version] => 1.0
    [encoding] => UTF-8
    [standalone] => -1
    [type] => 9
    [compression] => -1
    [charset] => 1
    [0] => 4
    [1] => 138267176
    [children] => Array
        (
            [0] => domelement Object
                (
                    [type] => 1
                    [tagname] => XML_DOC
                    [0] => 5
                    [1] => 138267304
                    [children] => Array
                        (
                            [0] => domtext Object
                                (
                                    [type] => 3
                                    [name] => #text
                                    [content] =>
         something inside the CDATA.

                                    [0] => 6
                                    [1] => 138258296
                                )

                        )

                )

        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-05 14:56 UTC] galg at sphera dot com
I've compiled now the php myself:
 - I compiled php 4.3.10 with libxml2-2.4.30 the result was ok as i expected to be.
 - I compiled php 4.3.10 with libxml2 20611 the result was the same i wrote in the bug description.

Latest version of libxml2 is :2.6.17.
The sources files of the libxml2 are under directory called "old" all new Linux distributions are using libxml2 version 2.6.x.
 [2005-02-05 16:03 UTC] galg at sphera dot com
Made 2 more tests:
I've compiled php 4.3.10 with the latest libxml2 ver 2.6.17 and still has the same problem

I tried also to compile it agains version libxml2-2.5.11 and it worked as expected.

The problem seems to be only with version 2.6.x of libxml2.
 [2005-02-06 00:18 UTC] galg at sphera dot com
It's seems to be a problem with the integration of PHP 4.3.x and libxml2 ver 2.6.x.

I've tested the following php5 script on PHP 5.0.2 compiled with libxml2-2.6.11 and it worked as expected:

<?php
$sXML = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<XML_DOC>
        <![CDATA[ something inside the CDATA.  ]]>
</XML_DOC>
XML;

$objXML = new DOMDocument;
$objXML->loadXML($sXML);

foreach ($objXML->documentElement->childNodes as $child)
{
        echo "Type: " . $child->nodeType . "\t | \t";
        echo "Name: " . $child->nodeName;
        echo "\n";
}
?>


The php5 script returns good result: the CDATA section with type 4.
Could it be that the problem is an API change in the libxml2 version 2.6.x which wasn't updated in version 4.3.x of php ?

The result of the script on my environment is:
Type: 3  |      Name: #text
Type: 4  |      Name: #cdata-section
Type: 3  |      Name: #text

Regards,
Gal
 [2005-02-06 07:01 UTC] sniper@php.net
Rob, can you please check this out?

 [2005-02-07 22:12 UTC] rrichards@php.net
This change was necessary as libxml 2.6 broke a bunch of domxml's xsl stuff. This would require an API change to be able to support loading CDATA. domxml behavior when using libxml 2.6+ and loading a document now converts incoming CDATA to TEXT nodes. This does not affect creating CDATA manually however.
 [2005-02-08 14:22 UTC] galg at sphera dot com
Hello Rob.

Thanks for the update.
The problem is that the updated Linux distributions are using libxml2 version 2.6 and most of the production servers which are running PHP are using the distibution binary package.

Not fixing this bug means that people have to change their code lines which were written as described in the php documentation of DomXML and used to work.

Please reconsider fixing this bug.

Regards,
Gal
 [2005-02-08 23:19 UTC] rrichards@php.net
Even it were to be fixed, people would need to change their code as an api change is required. The reason is that its possible to use the cdata as text in libxml, but there was no way to fix the xsl issues without an api change. had to decide against the lesser of 2 evils here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 19:01:29 2024 UTC