function createTextElement($text) { $node = new Node(); $node->setType(TEXTELEMENT); $node->setValue($text); 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); }
/** * @param array $config * @param array $params * @throws ApiRequestException */ public function __construct(array $config, array $params = []) { $filterNode = new Node('filter'); if (isset($params['key'])) { $filterNode->setValue(new Node('key', $params['key'])); } if (isset($params['keys']) && is_array($params['keys'])) { $nodes = []; foreach ($params['keys'] as $key) { $nodes[] = new Node('key', $key); } $filterNode->setValue(new NodeList($nodes)); } $params['filter'] = $filterNode; parent::__construct($config, $params); }
/** * 头插法 * @param unknown_type $value */ public function insertFirst($value) { $new = new Node(null, $value); $new->setValue($value); $new->next = $this->head->next; $this->head->next = $new; }
/** * Read an individual type from the stream. * * @param resource $fPtr Stream pointer * @param int $tagType Tag to read * @param Node $node Node to add data to * * @return mixed */ private function readType($fPtr, $tagType, Node $node) { switch ($tagType) { case Tag::TAG_BYTE: // Signed byte (8 bit) $node->setValue($this->dataHandler->getTAGByte($fPtr)); break; case Tag::TAG_SHORT: // Signed short (16 bit, big endian) $node->setValue($this->dataHandler->getTAGShort($fPtr)); break; case Tag::TAG_INT: // Signed integer (32 bit, big endian) $node->setValue($this->dataHandler->getTAGInt($fPtr)); break; case Tag::TAG_LONG: // Signed long (64 bit, big endian) $node->setValue($this->dataHandler->getTAGLong($fPtr)); break; case Tag::TAG_FLOAT: // Floating point value (32 bit, big endian, IEEE 754-2008) $node->setValue($this->dataHandler->getTAGFloat($fPtr)); break; case Tag::TAG_DOUBLE: // Double value (64 bit, big endian, IEEE 754-2008) $node->setValue($this->dataHandler->getTAGDouble($fPtr)); break; case Tag::TAG_BYTE_ARRAY: // Byte array $node->setValue($this->dataHandler->getTAGByteArray($fPtr)); break; case Tag::TAG_STRING: // String $node->setValue($this->dataHandler->getTAGString($fPtr)); break; case Tag::TAG_INT_ARRAY: $node->setValue($this->dataHandler->getTAGIntArray($fPtr)); break; case Tag::TAG_LIST: // List $tagID = $this->dataHandler->getTAGByte($fPtr); $listLength = $this->dataHandler->getTAGInt($fPtr); // Add a reference to the payload type $node->setPayloadType($tagID); for ($i = 0; $i < $listLength; ++$i) { if (feof($fPtr)) { break; } $listNode = new Node(); $this->readType($fPtr, $tagID, $listNode); $node->addChild($listNode); } break; case Tag::TAG_COMPOUND: // Compound // Uck. Don't know a better way to do this, $compoundNode = new Node(); while ($this->traverseTag($fPtr, $compoundNode)) { $node->addChild($compoundNode); // Reset the node for adding the next tags $compoundNode = new Node(); } break; } }