Thursday, 19 September 2013

removing nodes from xml incomplete, needs several runs

removing nodes from xml incomplete, needs several runs

I have a very strange bug I am trying to figure out. I load in an xml,
find a specific node, then delete it, then save the file. But when I run
it, it only catches SOME of those nodes on the first run, then some more
on the second and third runs until it finally finishes. There is no reason
I can figure why this is happening. Here is my code:
foreach(glob("*.xml") as $filename) {
$domsrc = file_get_contents($filename, FILE_TEXT);
$MYdom = new DomDocument();
$MYdom->loadXML($domsrc);
foreach ($MYdom->getElementsByTagName('URL') as $virttour) {
if($virttour->getAttribute('Type') == 'Virtual Tour') {
$virttour->parentNode->removeChild($virttour);
}
}
$MYdom->save($filename);

No comments:

Post a Comment