Forums / Extensions / Website Interface / Visual editor - error while save document / Comment55404
Bastian Fenske
Tuesday 15 April 2008 2:13:13 am
This works for me:
// Remove only nodes that don't match schema (recursively) function fixSubtree( $element, &$mainChild ) { $parent = $element->parentNode; $mainParent = $mainChild->parentNode; if ( $element->hasChildNodes() ) { // http://php.net/manual/en/domnode.removechild.php#56556 $childNodes = array(); foreach($element->childNodes as $childNode) { $childNodes[] = $childNode; } foreach ($childNodes as $childNode) { $childNode = $childNode->parentNode->removeChild($childNode); $childNode = $mainParent->insertBefore( $childNode, $mainChild ); if ( !$this->XMLSchema->check( $mainParent, $childNode ) ) { $this->fixSubtree( $childNode, $mainChild ); } } } $element = $parent->removeChild( $element ); }
Basti