/** * Calculate payload * * @param com.google.gsa.feed.XmlFeed feed * @return string */ public function payload($feed) { $tree = new Tree('gsafeed'); $tree->addChild((new Node('header'))->withChild(new Node('datasource', $feed->dataSource()))->withChild(new Node('feedtype', $feed->feedType()->name()))); $group = $tree->addChild(new Node('group')); foreach ($feed->getRecords() as $record) { $record->visit($group->addChild(new Node('record'))); } return $tree->getDeclaration() . "\n" . self::FEED_DOC_TYPE . "\n" . $tree->getSource(INDENT_DEFAULT); }
public function performance() { $s = microtime(true); $t = new Tree(); for ($i = 0; $i < 100; $i++) { $c = $t->addChild(new \xml\Node('child', null, array('id' => $i))); for ($j = 0; $j < 100; $j++) { $c->addChild(new \xml\Node('elements', str_repeat('x', $j))); } } $l = strlen($t->getSource(INDENT_NONE)); printf('%d bytes, %.3f seconds', $l, microtime(true) - $s); }
/** * 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(), []); return $tree->getSource(INDENT_DEFAULT); }