php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38562 DOM Function saveXML
Submitted: 2006-08-23 10:35 UTC Modified: 2006-08-23 13:33 UTC
From: dandrikop at cosmote dot gr Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.1.5 OS: Fedora Core 5
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dandrikop at cosmote dot gr
New email:
PHP Version: OS:

 

 [2006-08-23 10:35 UTC] dandrikop at cosmote dot gr
Description:
------------
I use the new DOM extension of PHP5. I want to pass special characters manually in the XML CDATA tags, but special characters such as '&' are automatically escaped.

Reproduce code:
---------------
<?php

        $imp = new DOMImplementation();
        $dtd = $imp->createDocumentType( 'clickAPI', null, 'xml_dtd.txt' );
        $xml_request = $imp->createDocument( null, null, $dtd );
        $xml_request->version = '1.0';
        $xml_request->formatOutput = true;


        // Create the tag 'clickAPI'.
        $clickAPI = $xml_request->appendChild(  new DOMElement( 'clickAPI' )  );

        // Create the tag 'sendMsg'.
        $sendMsg = $clickAPI->appendChild(  new DOMElement( 'sendMsg' )  );

        // Add elements under the 'auth' tag.
        $sendMsg->appendChild(  new DOMElement( 'session_id', 'aaaaaaaaaaaaaaaaa' )  );

//      $sendMsg->appendChild(  new DOMElement( 'text', "Test &#10;" )  );
        $text = $sendMsg->appendChild(  new DOMElement( 'text' )  );
        $text->appendChild(  new DOMText( "Test &#10;" )  );

        $sendMsg->appendChild(  new DOMElement( 'to', '306978888888' )  );


        if( @$xml_request->validate() ){
                echo "OK\n";
        } else {
                echo "Not OK!\n";
        }

        echo "\n" . $xml_request->saveXML() . "\n";
?>

Expected result:
----------------
OK

<?xml version="1.0"?>
<!DOCTYPE clickAPI SYSTEM "xml_dtd.txt">
<clickAPI>
  <sendMsg>
    <session_id>aaaaaaaaaaaaaaaaa</session_id>
    <text>Test &#10;</text>
    <to>306978888888</to>
  </sendMsg>
</clickAPI>

Actual result:
--------------
OK

<?xml version="1.0"?>
<!DOCTYPE clickAPI SYSTEM "xml_dtd.txt">
<clickAPI>
  <sendMsg>
    <session_id>aaaaaaaaaaaaaaaaa</session_id>
    <text>Test &amp;#10;</text>
    <to>306978888888</to>
  </sendMsg>
</clickAPI>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-23 13:16 UTC] dandrikop at cosmote dot gr
I used the following line and I got exactly what I had input:

==============================
print $xml_request->getElementsByTagName( 'text' )->item(0)->nodeValue . "\n";
==============================

Result:
Test &#10;
 [2006-08-23 13:22 UTC] tony2001@php.net
See explanation in bug #26650.
 [2006-08-23 13:33 UTC] dandrikop at cosmote dot gr
Thanks for the reply. The bug #26650 was actually the same problem. So I guess that I have to write my own saveXML() function.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 11:02:27 2025 UTC