So I want to delete a child from an XML string where an attribute is a specific value.
For Example:
<xml>
<note url="http://google.com">
Values
</note>
<note url="http://yahoo.com">
Yahoo Values
</note>
</xml>
So how would I delete the note node with attribute http://yahoo.com as the string for the URL?
I'm trying to do this in PHP Simple XML
Oh and also I'm loading it in as an XML Object with the SimpleXML_Load_String function like this:
$notesXML = simplexml_load_string($noteString['Notes']);
It is possible to remove nodes with SimpleXML by using
unset()
, though there is some trickery to it.If there are multiple matching nodes that you wish to delete, you could loop over them.
SimpleXML does not have the remove child node feature,
there are cases you are can do How to deleted an element inside XML string?
but is depend on XML structure
Solution in DOMDocument