code/pagetypes/BrowseCataloguePage.php
/**
     * Transform a nested XML structure into a nested PHP array structure.
     *
     * @param DOMNode $node to be transformed
     *
     * @return array|string
     */
Transform a nested XML structure into a nested PHP array structure.
@param DOMNode $node to be transformed

@return array|string
Transform a nested XML structure into a nested PHP array structure . @param DOMNode $node to be transformed @return array|string
protected function XML2PHP($node)
    {
        if ($node->nodeType == XML_TEXT_NODE) return trim($node->textContent);
        if (isset($node->childNodes) && $node->childNodes->length == 1 && $node->childNodes->item(0)->nodeType == XML_TEXT_NODE) return $this->XML2PHP($node->childNodes->item(0));
        $php = [];
        foreach ($node->childNodes as $child) {
            $value = $this->XML2PHP($child);
            if (empty($value)) continue;
            if (is_array($value)) $value = ArrayList::create(array_values($value));
            if (isset($php[$child->nodeName])) {
                if ($php[$child->nodeName]['Value'] instanceof ArrayList) {
                    $php[$child->nodeName]['Value']->push(ArrayData::create(['Value' => $value]));
                } else {
                    $php[$child->nodeName]['Value'] = ArrayList::create([
                        ArrayData::create(['Value' => $php[$child->nodeName]['Value']]),
                        ArrayData::create(['Value' => $value])
                    ]);
                }
            } else {
                $php[$child->nodeName] = [
                    'Label' => FormField::name_to_label(ucfirst($child->localName)),
                    'Value' => $value,
                ];
            }
        }
        return $php;
    }
protected function XML2PHP ( $ node ) { if ( $ node -> nodeType == XML_TEXT_NODE ) return trim ( $ node -> textContent ) ; if ( isset ( $ node -> childNodes ) && $ node -> childNodes -> length == 1 && $ node -> childNodes -> item ( 0 ) -> nodeType == XML_TEXT_NODE ) return $ this -> XML2PHP ( $ node -> childNodes -> item ( 0 ) ) ; $ php = [ ] ; foreach ( $ node -> childNodes as $ child ) { $ value = $ this -> XML2PHP ( $ child ) ; if ( empty ( $ value ) ) continue ; if ( is_array ( $ value ) ) $ value = ArrayList :: create ( array_values ( $ value ) ) ; if ( isset ( $ php [ $ child -> nodeName ] ) ) { if ( $ php [ $ child -> nodeName ] [ 'Value' ] instanceof ArrayList ) { $ php [ $ child -> nodeName ] [ 'Value' ] -> push ( ArrayData :: create ( [ 'Value' => $ value ] ) ) ; } else { $ php [ $ child -> nodeName ] [ 'Value' ] = ArrayList :: create ( [ ArrayData :: create ( [ 'Value' => $ php [ $ child -> nodeName ] [ 'Value' ] ] ) , ArrayData :: create ( [ 'Value' => $ value ] ) ] ) ; } } else { $ php [ $ child -> nodeName ] = [ 'Label' => FormField :: name_to_label ( ucfirst ( $ child -> localName ) ) , 'Value' => $ value , ] ; } } return $ php ; }
Transform a nested XML structure into a nested PHP array structure.
Transform a nested XML structure into a nested PHP array structure .