protected function createMetadataElement(MetadataValue $metadata, DOMElement $metadataNode, $map, DOMDocument $imsManifest)
    {
        $path = $metadata->getPath();
        $path = array_reverse($path);

        $uniqNodes = [];
        if ($metadata instanceof ClassificationValue) {
            $uniqNodes = array('taxonPath', 'source');
        }

        $oldChildNode = null;
        foreach($path as $index => $element) {
            $name = substr($element,(strpos($element,'#') + 1));
            $base = substr($element,0,(strpos($element,'#')));

            if (in_array($name, $uniqNodes) || is_null($oldChildNode) || $metadataNode->getElementsByTagName($map[$base].':'.$name)->length === 0) {
                $node = $imsManifest->createElement($map[$base].':'.$name);
            } else {
                $node = $metadataNode->getElementsByTagName($map[$base].':'.$name)->item(0);
            }

            if($name == 'string' || $name == 'langstring'){
                $node->setAttribute('xml:lang', $metadata->getLanguage());
            }

            if(isset($oldChildNode)){
                $node->appendChild($oldChildNode);
                if ($name == 'taxonPath' && $metadata instanceof ClassificationMetadataValue) {
                    foreach ($metadata->getEntries() as $entry) {
                        $this->createMetadataElement($entry, $node, $map, $imsManifest);
                    }
                }
            } else{
                $node->nodeValue = $metadata->getValue();
            }
            $oldChildNode = $node;
        }

        $metadataNode->appendChild($oldChildNode);
    }
protected function createMetadataElement(MetadataValue $metadata, DOMElement $metadataNode, $map, DOMDocument $imsManifest)
    {
        $path = $metadata->getPath();
        $path = array_reverse($path);

        $uniqNodes = [];
        if ($metadata instanceof ClassificationValue) {
            $uniqNodes = array('taxonPath', 'source');
        }

        $oldChildNode = null;
        foreach($path as $index => $element) {
            $name = substr($element,(strpos($element,'#') + 1));
            $base = substr($element,0,(strpos($element,'#')));

            if (in_array($name, $uniqNodes) || is_null($oldChildNode) || $metadataNode->getElementsByTagName($map[$base].':'.$name)->length === 0) {
                $node = $imsManifest->createElement($map[$base].':'.$name);
            } else {
                $node = $metadataNode->getElementsByTagName($map[$base].':'.$name)->item(0);
            }

            if($name == 'string' || $name == 'langstring'){
                $node->setAttribute('xml:lang', $metadata->getLanguage());
            }

            if(isset($oldChildNode)){
                $node->appendChild($oldChildNode);
                if ($name == 'taxonPath' && $metadata instanceof ClassificationMetadataValue) {
                    foreach ($metadata->getEntries() as $entry) {
                        $this->createMetadataElement($entry, $node, $map, $imsManifest);
                    }
                }
            } else{
                $node->nodeValue = $metadata->getValue();
            }
            $oldChildNode = $node;
        }

        $metadataNode->appendChild($oldChildNode);
    }
protected function createMetadataElement ( MetadataValue $ metadata , DOMElement $ metadataNode , $ map , DOMDocument $ imsManifest ) { $ path = $ metadata -> getPath ( ) ; $ path = array_reverse ( $ path ) ; $ uniqNodes = [ ] ; if ( $ metadata instanceof ClassificationValue ) { $ uniqNodes = array ( 'taxonPath' , 'source' ) ; } $ oldChildNode = null ; foreach ( $ path as $ index => $ element ) { $ name = substr ( $ element , ( strpos ( $ element , '#' ) + 1 ) ) ; $ base = substr ( $ element , 0 , ( strpos ( $ element , '#' ) ) ) ; if ( in_array ( $ name , $ uniqNodes ) || is_null ( $ oldChildNode ) || $ metadataNode -> getElementsByTagName ( $ map [ $ base ] . ':' . $ name ) -> length === 0 ) { $ node = $ imsManifest -> createElement ( $ map [ $ base ] . ':' . $ name ) ; } else { $ node = $ metadataNode -> getElementsByTagName ( $ map [ $ base ] . ':' . $ name ) -> item ( 0 ) ; } if ( $ name == 'string' || $ name == 'langstring' ) { $ node -> setAttribute ( 'xml:lang' , $ metadata -> getLanguage ( ) ) ; } if ( isset ( $ oldChildNode ) ) { $ node -> appendChild ( $ oldChildNode ) ; if ( $ name == 'taxonPath' && $ metadata instanceof ClassificationMetadataValue ) { foreach ( $ metadata -> getEntries ( ) as $ entry ) { $ this -> createMetadataElement ( $ entry , $ node , $ map , $ imsManifest ) ; } } } else { $ node -> nodeValue = $ metadata -> getValue ( ) ; } $ oldChildNode = $ node ; } $ metadataNode -> appendChild ( $ oldChildNode ) ; }
Add an element based on MetadataValue object to DomDocument

@param MetadataValue $metadata
@param DOMElement $metadataNode
@param $map
@param DOMDocument $imsManifest
Add an element based on MetadataValue object to DomDocument