/** * Returns an XML tree for use in further test cases * * @return xml.Tree */ protected function personTree() { $t = new Tree('person'); $t->root()->setAttribute('id', '1549'); $t->addChild(new \xml\Node('firstName', 'Timm')); $t->addChild(new \xml\Node('lastName', 'Friebe')); $t->addChild(new \xml\Node('location', 'Karlsruhe')); $t->addChild(new \xml\Node('location', 'Germany')); return $t; }
/** * 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); }