/** * Serialize * * @param var value * @return string */ public function serialize($payload) { $t = new Tree(); $t->setEncoding('UTF-8'); if ($payload instanceof Payload) { $root = isset($payload->properties['name']) ? $payload->properties['name'] : 'root'; $payload = $payload->value; } else { $root = 'root'; } if ($payload instanceof Generic || is_array($payload)) { $t->root = Node::fromArray($this->convert($payload), $root); } else { $t->root = new Node($root, $this->convert($payload)); } return $t->getDeclaration() . "\n" . $t->getSource(INDENT_NONE); }
/** * Set XML from a tree * * @param xml.Tree xml */ public function setXMLTree(Tree $xml) { libxml_get_last_error() && libxml_clear_errors(); $this->document = new DOMDocument(); $this->document->loadXML($xml->getDeclaration() . $xml->getSource(INDENT_NONE)); $this->_checkErrors($xml); }
/** * Marshal an object to xml * * @param lang.Object instance * @param xml.QName qname default NULL * @return string xml * @deprecated Use marshalTo() instead */ public static function marshal($instance, $qname = NULL) { $class = $instance->getClass(); // Create XML tree and root node. Use the information provided by the // qname argument if existant, use the class` non-qualified (and // lowercased) name otherwise. $tree = new Tree(); if ($qname) { $prefix = $qname->prefix ? $qname->prefix : $qname->localpart[0]; $tree->root()->setName($prefix . ':' . $qname->localpart); $tree->root()->setAttribute('xmlns:' . $prefix, $qname->namespace); } else { if ($class->hasAnnotation('xmlns')) { $tree->root()->setName($class->getSimpleName()); } else { $tree->root()->setName(strtolower($class->getSimpleName())); } } self::recurse($instance, $class, $tree->root(), array()); return $tree->getSource(INDENT_DEFAULT); }
public function performance() { $s = microtime(TRUE); $t = new Tree(); for ($i = 0; $i < 100; $i++) { $c = $t->addChild(new Node('child', NULL, array('id' => $i))); for ($j = 0; $j < 100; $j++) { $c->addChild(new Node('elements', str_repeat('x', $j))); } } $l = strlen($t->getSource(INDENT_NONE)); printf('%d bytes, %.3f seconds', $l, microtime(TRUE) - $s); }
/** * Returns the full XML source of the 'dia' diagram * * @return string XML representation of the DIAgramm */ public function getSource($indent = INDENT_DEFAULT) { $Node = $this->getNode(); $Tree = new Tree(); $Tree->root = $Node; return $Tree->getDeclaration() . "\n" . $Tree->getSource($indent); }