Jump to content

Deleting an XML node


blinks58

Recommended Posts

I'm trying to delete the <identifier> node of some XML, using the following code; unsuccessfully.

 

Can someone help me identify where I'm going wrong? TIA

$newXML = "";
$xmlString = Fedora_API::callGetDatastreamContents($this->pid, 'MODS', true);
$doc = DOMDocument::loadXML($xmlString);
$xpath = new DOMXPath($doc);

$fieldNodeList = $xpath->query("/identifier");

foreach ($fieldNodeList as $node) {  
	$fieldNodeList->removeChild($node);
}
$newXML = $doc->SaveXML();  
Link to comment
https://forums.phpfreaks.com/topic/288771-deleting-an-xml-node/
Share on other sites

Solved:

$newXML = "";
$xmlString = Fedora_API::callGetDatastreamContents($this->pid, 'MODS', true);
$doc = DOMDocument::loadXML($xmlString);
$xpath = new DOMXPath($doc);
                                
$fieldNodeList = $xpath->query("/identifier");

foreach($fieldNodeList as $node){
                $node->parentNode->removeChild($node); 
}
                                
$newXML = $doc->SaveXML();  /

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.