public function slice($start_index, $end_index = NULL) {
    if ($start_index < 0) {
      $start_index = $this->count() + $start_index;
    }
    if ($end_index < 0) {
      $end_index = $this->count() + $end_index;
    }
    $last_index = $this->count() - 1;
    if ($start_index > $last_index) {
      $start_index = $last_index;
    }
    if ($end_index !== NULL) {
      if ($end_index > $last_index) {
        $end_index = $last_index;
      }
      if ($start_index > $end_index) {
        $start_index = $end_index;
      }
      $length = $end_index - $start_index;
    }
    else {
      $length = $this->count() - $start_index;
    }
    return new NodeCollection(array_slice($this->nodes, $start_index, $length));
  }