php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48916 Add feature to delete XML node in SimpleXML when node selected by xpath
Submitted: 2009-07-14 14:53 UTC Modified: 2009-07-14 15:41 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: piotr dot baranowski at zeno dot pl Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.10 OS: All of them
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: piotr dot baranowski at zeno dot pl
New email:
PHP Version: OS:

 

 [2009-07-14 14:53 UTC] piotr dot baranowski at zeno dot pl
Description:
------------
Just as in the title. There's no way now to delete XML node in SimpleXML. It would be nice to have SimpleXML method that would delete given node.

Reproduce code:
---------------
---
From manual page: book.simplexml
---



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-14 15:09 UTC] rrichards@php.net
no need for additional method. unset() performs deletions
 [2009-07-14 15:41 UTC] piotr dot baranowski at zeno dot pl
Sorry, i forgot to write that this is about nodes selected by xpath ;-)
Yeah, i know, so lame of me.

<?php
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>
<root>
<recipes>
<recipe>
	<id>1</id>
</recipe>
<recipe>
	<id>2</id>
</recipe>
</recipes>
</root>');
print_r($xml);

$node = $xml->xpath('recipes/recipe[id="1"]');
$foo = &$node[0];

unset($node[0]);
$node[0] = null;

unset($foo);
$foo = null;

print_r($xml);
?>

print_r gives same result before and after unset or setting node to null. It's because only the reference, not content of reference, is unset().

There's no way to delete (or no way that i could thought about) to delete node selected by xpath.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC