function createElement($name) { $node = new Node(); $node->setName($name); $node->setType(ELEMENT); return $node; }
/** * Converts an XML string into an object struct. * * @param string $data The XML string * * @return esXml The parsed XML */ private function xmlToObject($data) { $root = new Node(); $root->setName('root'); $actualLevel = 1; $actualNode = $root; $stack = array(); $stack[1] = $root; foreach ($this->parseIntoStruct($data) as $element) { if ($element['type'] === 'close') { continue; } $node = new Node(); $node->setName($element['tag']); if (isset($element['attributes'])) { $node->setAttributes($element['attributes']); } if (isset($element['value'])) { $node->setValue($element['value']); } $level = $element['level']; if ($level > $actualLevel) { $stack[$level] = $actualNode; } $stack[$level]->addChild($node); $actualNode = $node; $actualLevel = $element['level']; } $children = $root->getChildren(); unset($root); return $children[0]->setParent(null); }
public function nameAccessors() { $n = new Node('node'); $n->setName('name'); $this->assertEquals('name', $n->getName()); }
/** * Read the next tag from the stream. * * @param resource $fPtr Stream pointer * @param Node $node Tree array to write to * * @return bool */ private function traverseTag($fPtr, Node &$node) { if (feof($fPtr)) { return false; } // Read type byte $tagType = $this->dataHandler->getTAGByte($fPtr); if ($tagType == Tag::TAG_END) { return false; } else { $node->setType($tagType); $tagName = $this->dataHandler->getTAGString($fPtr); $node->setName($tagName); $this->readType($fPtr, $tagType, $node); return true; } }
/** * @expectedException \InvalidArgumentException */ public function testSetNameMethodException() { $this->object->setName('foo'); $this->object->setName('baz'); }
/** * Adds a child to the current node. * * @param string $name * @param Node $node */ public function __set($name, $node) { if ($node instanceof static) { $this->addChild($node->setName($name)); } }