public function cloneNode()
 {
     // clone the calling node
     if (self::DEBUG) {
         u\DebugUtility::out("Parent ID: " . $this->parent_id);
     }
     $clone_obj = new StructuredDataNode($this->toStdClass(), NULL, $this->data_definition, 0, $this->parent_id);
     if (self::DEBUG) {
         u\DebugUtility::dump($clone_obj->toStdClass());
     }
     // work out the new identifier
     $this_identifier = $this->identifier;
     if (self::DEBUG) {
         u\DebugUtility::out($this_identifier);
     }
     $index = self::getLastIndex($this->identifier) + 1;
     $clone_identifier = self::removeLastIndex($this->identifier) . self::DELIMITER . $index;
     $clone_obj->identifier = $clone_identifier;
     if (self::DEBUG) {
         u\DebugUtility::out($clone_identifier);
     }
     return $clone_obj;
 }
 private function removeLastNodeFromField($field_name)
 {
     if (!$this->data_definition->hasIdentifier($field_name)) {
         throw new e\NoSuchFieldException(S_SPAN . "The field name {$field_name} does not exist." . E_SPAN);
     }
     if (!$this->data_definition->isMultiple($field_name)) {
         throw new e\NodeException(S_SPAN . "The field {$field_name} is not multiple." . E_SPAN);
     }
     $first_node = $this->getNode($field_name . a\DataDefinition::DELIMITER . '0');
     $par_id = $first_node->getParentId();
     if ($par_id == '') {
         $last_pos = StructuredDataNode::getPositionOfLastNode($this->children, $field_name);
         $first_pos = StructuredDataNode::getPositionOfFirstNode($this->children, $field_name);
         $last_id = $this->children[$last_pos]->getIdentifier();
         if ($first_pos == $last_pos) {
             throw new e\NodeException(S_SPAN . "Cannot remove the only node in the field." . E_SPAN);
         }
         $child_count = count($this->children);
         if ($child_count > $last_pos) {
             $before = array_slice($this->children, 0, $last_pos);
             $after = array_slice($this->children, $last_pos + 1);
             $this->children = array_merge($before, $after);
         }
     } else {
         $this->getNode($par_id)->removeLastChildNode($field_name);
     }
     if (isset($last_id) && isset($this->node_map[$last_id])) {
         unset($this->node_map[$last_id]);
     }
     $this->identifiers = array_keys($this->node_map);
     return $this;
 }