private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int &$segmentIdx, array &$array, array &$errors)
    {
        // init
        $segmentVisited = false;

        for ($i = 0; $i < $elm['maxrepeat']; $i++) {

            if (\call_user_func($this->comparisonFunction, $message[$segmentIdx], $elm)) {

                $jsonMessage = $this->processSegment($message[$segmentIdx], $this->xmlSeg, $segmentIdx, $errors);
                $segmentVisited = true;
                $this->doAddArray($array, $jsonMessage);
                $segmentIdx++;

            } else {

                if (!$segmentVisited && isset($elm['required'])) {
                    $fixed = false;

                    if ($elm['replacewith'] !== null) {
                        $elmType = (string)$elm['replacewith'];
                    } else {
                        $elmType = (string)$elm['id'];
                    }

                    if (isset($this->segmentTemplates[$elmType])) {
                        $jsonMessage = $this->processSegment($this->segmentTemplates[$elmType], $this->xmlSeg, $segmentIdx, $errors);
                        $fixed = true;
                        $this->doAddArray($array, $jsonMessage);
                    }

                    $errors[] = [
                        "text"      => $this->messageTextConf['MISSINGREQUIREDSEGMENT'] . " " . ($fixed ? '(patched)' : ''),
                        "position"  => $segmentIdx,
                        "segmentId" => (string)$elm['id'],
                    ];
                }

                return;
            }
        }
    }