php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14817 Feature: copying/paste nodes to each other
Submitted: 2002-01-02 21:34 UTC Modified: 2002-01-02 21:40 UTC
From: r dot klinkenberg at student dot utwente dot nl Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 4.1.1 OS:
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: r dot klinkenberg at student dot utwente dot nl
New email:
PHP Version: OS:

 

 [2002-01-02 21:34 UTC] r dot klinkenberg at student dot utwente dot nl
Currently I'm building system that stores xml data in a database. When I get this data out of m database and try to put it into a node, all the xml inside is escaped.

For example:
-----------------------------------------------------------
$xml = '<list>
<item>first</item>
<item>second</item>
</list>';

$D_doc  = new_xmldoc("1.0");
$D_root = $D_doc->add_root('page');
$D_node = $D_root->new_child('posting', $xml);

Header('Content-type: text/xml');
echo $D_doc->dumpmem();
-----------------------------------------------------------

Will output the following data:
-----------------------------------------------------------
<?xml version="1.0"?>
<page><posting>&lt;list&gt;
&lt;item&gt;first&lt;/item&gt;
&lt;item&gt;second&lt;/item&gt;
&lt;/list&gt;</posting></page>
-----------------------------------------------------------

Often that is not desired. Therefore I hoped it should be possible to 'copy/paste' dom objects. If that would be possible, I could do something like this:

Example:
-----------------------------------------------------------
$xml = '<list>
<item>first</item>
<item>second</item>
</list>';

$D_doc  = new_xmldoc("1.0");
$D_root = $D_doc->add_root('page');

// Create DOM object from the data
$D_posting = xmldoc('<?xml version="1.0"?><posting>' . $xml . '</posting>');
// Paste the root of $D_posting to the first DOM document
$D_node = $D_root->add_node($D_posting);

Header('Content-type: text/xml');
echo $D_doc->dumpmem();
-----------------------------------------------------------

What should output:
-----------------------------------------------------------
<?xml version="1.0" ?> 
<page>
  <posting>
    <list>
      <item>first</item>
      <item>second</item>
    </list>
  </posting> 
</page>
-----------------------------------------------------------

Currently I'm using a xmltree() to make a DOM document from $xml. The result from xmltree() is that recursively walked through and the nodes that are found are added to the first DOM document.

Hopefully there is a way to implement the direct copying of dom object, like eg. in Java.

--
Rense

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-02 21:40 UTC] mfischer@php.net
Thats the (intended) behaviour of libxml2 and there's little PHP can do about it.

And libxml2 certainly is not designed to handle the way you like to add xml data to your document. You'll have to use the native domxml function PHP provides to construct your XML.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 18:01:32 2019 UTC