php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15530 content of node node correct reading new DOM value after set_content of node
Submitted: 2002-02-12 16:18 UTC Modified: 2002-02-21 11:06 UTC
From: rrichards at digarc dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.1.1 OS: RedHat 7.2
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: rrichards at digarc dot com
New email:
PHP Version: OS:

 

 [2002-02-12 16:18 UTC] rrichards at digarc dot com
The following simplied script shows that when we update the value of a node, the DOM is updated as shown through the dump.  When you try to read the content of the node however, it returns the origional value.  

If this is a bug, is there any known workaround to get the desired result?

Also, we had to use the set_content as provided in the script because if a node already has a value and we try to call set_content directly on the node rather than on the the text element (value node), it appends the data to the node rather than overwriting the exisitng value.

XPath is used in here as our real XML data is quite complex so needed to illustrate how we were finding the correct node.

<?
$xmltest = "<root_node><node1>ORG VALUE</node1></root_node>";
$mydoc = xmldoc($xmltest);
echo "<pre>".$mydoc->dumpmem()."</pre><br>";
$ctx=$mydoc->xpath_new_context();
$query_xo = xpath_eval($ctx,"/root_node/node1");
$oNode = $query_xo->nodeset[0];
if (is_null($oNode)) {
	$root = $$mydoc->root();
	$root->new_child("node1", "empty");
} else {
	$tNode = $oNode->first_child();
	$tNode->set_content("VALUE1");
}
echo "<pre>".$mydoc->dumpmem()."</pre><br>";
$ctx2=$mydoc->xpath_new_context();
$query_xo = xpath_eval($ctx2,"/root_node/node1");
$oNode = $query_xo->nodeset[0];
if (! is_null($oNode)) {
	$tNode = $oNode->first_child();
	$strValue = $tNode->content;
}
echo "<br>GET VAL".$strValue."<br>";
echo "<pre>".$mydoc->dumpmem()."</pre>";
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-13 10:43 UTC] jtate at mi-corporation dot NOSPAM dot com
The problem is that the content property is going away, so that property is not set.  This is why it's not being updated.  It's being replaced by a get_content() function.  This is in CVS at this very moment.

As for the appending of xml contents, the comment in the code is as follows:
// FIXME: another gotcha. If node has children, calling
// xmlNodeSetContent will remove the children -> we loose the zval's
// To prevent crash, append content if children are set


I think if you just used the get_content() function instead of the ->content property that your problem would go away.  Of course you're going to have to pull it from CVS.
 [2002-02-13 11:03 UTC] rrichards at digarc dot com
Any other workaround for the get_content problem?  We can use a custom php build on our development machines, but cant on the server where the code will actually be going.

Thanks
 [2002-02-21 11:06 UTC] jtate@php.net
This bug has been fixed in CVS.

This has been fixed in CVS with the get_content() method.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC