/** * Parse the XML of a view object, * check the node type and name * and add the proper XML part of child tags * to the \DOMDocument of the current tag * * @param \DOMDocument $dom * @param \DOMNode $reference Current XML structure * @param bool $emptyElement * @return bool */ protected function parseXML(\DOMDocument $dom, \DOMNode $reference, $emptyElement = FALSE) { $node = $reference->firstChild; while (!is_null($node)) { $deleteNode = FALSE; $nodeType = $node->nodeType; $nodeName = $node->nodeName; switch ($nodeType) { case XML_TEXT_NODE: break; case XML_ELEMENT_NODE: switch ($nodeName) { case 'containerWrap': $containerWrap = $this->render('containerWrap'); if ($containerWrap) { $this->replaceNodeWithFragment($dom, $node, $containerWrap); } else { $emptyElement = TRUE; } $deleteNode = TRUE; break; case 'elements': $replaceNode = $this->getChildElements($dom); if ($replaceNode) { $node->parentNode->replaceChild($replaceNode, $node); } else { $emptyElement = TRUE; } break; case 'label': if (!strrchr(get_class($this), 'AdditionalElement')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label')); } else { $replaceNode = $dom->createTextNode($this->model->getName()); $node->parentNode->insertBefore($replaceNode, $node); } } $deleteNode = TRUE; break; case 'legend': if (!strrchr(get_class($this), 'AdditionalElement')) { if ($this->model->additionalIsSet($nodeName)) { $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend')); } $deleteNode = TRUE; } break; case 'inputvalue': if (array_key_exists('checked', $this->model->getAllowedAttributes())) { if (!$this->model->hasAttribute('checked')) { $emptyElement = TRUE; } } elseif (array_key_exists('selected', $this->model->getAllowedAttributes()) && !$this->model->hasAttribute('selected')) { $emptyElement = TRUE; } else { $inputValue = $this->getInputValue(); if ($inputValue != '') { $replaceNode = $dom->createTextNode($this->getInputValue()); $node->parentNode->insertBefore($replaceNode, $node); } } $deleteNode = TRUE; break; case 'labelvalue': case 'legendvalue': $replaceNode = $dom->createTextNode($this->getAdditionalValue()); $node->parentNode->insertBefore($replaceNode, $node); $deleteNode = TRUE; break; } break; } // Parse the child nodes of this node if available if ($node->hasChildNodes()) { $emptyElement = $this->parseXML($dom, $node, $emptyElement); } // Get the current node for deletion if replaced. We need this because nextSibling can be empty $oldNode = $node; // Go to next sibling to parse $node = $node->nextSibling; // Delete the old node. This can only be done after going to the next sibling if ($deleteNode) { $oldNode->parentNode->removeChild($oldNode); } } return $emptyElement; }