dom = new DOMDocument('1.0', 'UTF-8'); $element = $this->dom->createElement('Formosite'); $element->setAttribute('id', $comp->getId()); $element->setAttribute('path', $comp->getPath()); $element->setAttribute('name', $comp->name); $element->setAttribute('title', $comp->title); $element->setAttribute('linkedForm', $comp->linkedForm); $this->dom->appendChild($element); array_push($this->elementStack, $element); } public function visitPage(Page $comp, $level) { $el = $this->dom->createElement('Page'); $el->setAttribute('id', $comp->getId()); $el->setAttribute('path', $comp->getPath()); $el->setAttribute('title', $comp->title); $parent = $this->handleParent($el, $level); $parent->appendChild($el); } public function visitField(Field $comp, $level) { $el = $this->dom->createElement('Field'); $el->setAttribute('id', $comp->getId()); $el->setAttribute('path', $comp->getPath()); $el->setAttribute('label', $comp->label); $el->setAttribute('type', $comp->type); $el->setAttribute('name', $comp->name); $el->setAttribute('value', $comp->value); $el->setAttribute('class', $comp->class); $el->setAttribute('info', $comp->info); $el->setAttribute('validIf', $comp->validIf); $el->setAttribute('okValues', $comp->okValues); $el->setAttribute('required', $comp->required); $el->setAttribute('disabled', $comp->disabled); $el->setAttribute('toBeSaved', $comp->toBeSaved); $el->setAttribute('infobulle', $comp->infobulle); $parent = $this->handleParent($el, $level); $parent->appendChild($el); } function visitBlock(Block $comp, $level) { return true; } public function handleParent(DomElement $child, $level) { $parent; if ($level > $this->current_level) { // child: add to stack $parent = $this->elementStack[count($this->elementStack) - 1]; array_push($this->elementStack, $child); } elseif ($level == $this->current_level) { // sibling: remove previous element and add child array_pop($this->elementStack); $parent = $this->elementStack[count($this->elementStack) - 1]; array_push($this->elementStack, $child); } elseif ($level < $this->current_level) { // ancestor: remove current and intervening elements $diff = ($this->current_level - $level) + 1; for ($x = 0; $x < $diff; $x++) { array_pop($this->elementStack); } $parent = $this->elementStack[count($this->elementStack) - 1]; array_push($this->elementStack, $child); } $this->current_level = $level; return $parent; } public function getXML() { return $this->dom->saveXML(); } public function toFile($file) { $this->dom->formatOutput = true; return $this->dom->save($file); } public function XSLTransform($xslfile) { $xslt = new XSLTProcessor(); $xml = new domDocument(); $xml->loadXML($this->dom->saveXML()); $xsl = new domDocument(); if (file_exists($xslfile)) { $xsl->load($xslfile); } else { return false; } $xslt -> importStylesheet($xsl); return $xslt -> transformToXml($xml); } } ?>