given a single ->data or ->struct element, return a parameter object in the new toolkit style.

@todo this needs more validation. It is possible that all parts are not set to create return

@param \SimpleXmlElement $dataElement
@return ProgramParameter
970130
public function singlePcmlToParam(\SimpleXmlElement $dataElement)
    {
        $tagName = $dataElement->getName();
    
        // get attributes of this element.
        $attrs = $dataElement->attributes();
    
        // both struct and data have name, count (optional), usage
        $name = (isset($attrs['name'])) ? (string) $attrs['name'] : '';
        $count = (isset($attrs['count'])) ? (string) $attrs['count'] : '';
        $usage = (isset($attrs['usage'])) ? (string) $attrs['usage'] : '';
        $structName = (isset($attrs['struct'])) ? (string) $attrs['struct'] : '';
    
        // fill this if we have a struct
        $subElements = array();
    
        // each item should have tag name <data>
        if ($tagName != 'data') {
            return false;
        }
    
        $type = (isset($attrs['type'])) ? (string) $attrs['type'] : '';

        // Get initial value, if specified by PCML.
        $dataValue = (isset($attrs['init'])) ? (string) $attrs['init'] : '';
        
        // if a struct then we need to recurse.
        if ($type == 'struct') {
            $theStruct = null; // init

            // look for matching struct definition encountered earlier.
            if ($this->_pcmlStructs) {

                // @todo verify type with is_array and count
                foreach ($this->_pcmlStructs as $possibleStruct) {
                    $possStructAttrs = $possibleStruct->attributes();
                    
                    if ($possStructAttrs['name'] == $structName) {
                        $theStruct = $possibleStruct;
                        $structAttrs = $possStructAttrs;
                        break;
                    }
                }
            }

            // if struct was not found, generate error for log
            if (!$theStruct) {
                // $this->getConnection->logThis("PCML structure '$structName' not found.");
                return null;
            }

            // count can also be defined at the structure level. If so, it will override count from data level)
            if (isset($structAttrs['count'])) {
                $count = (string) $structAttrs['count'];
            }

            // "usage" (in/out/inherit) can be defined here, at the structure level.
            $structUsage = (isset($structAttrs['usage'])) ? (string) $structAttrs['usage'] : '';

            // if we're not inheriting from our parent data element, but there is a struct usage, use the struct's usage (input, output, or inputoutput).
            if (!empty($structUsage) && ($structUsage != 'inherit')) {
                $usage = $structUsage;
            }

            $structSubDataElementsXmlObj = $theStruct->xpath('data');
            if ($structSubDataElementsXmlObj) {
                foreach ($structSubDataElementsXmlObj as $subDataElementXmlObj) {

                    if ($subDataElementXmlObj->attributes()->usage == 'inherit') {
                        // subdata is inheriting type from us. Give it to them.
                        $subDataElementXmlObj->attributes()->usage = $usage;
                    }

                    // here's where the recursion comes in. Convert data and add to array for our struct.
                    $subElements[] = $this->singlePcmlToParam($subDataElementXmlObj);
                }
            }
        }

        /* explanation of the terms "length" and "precision" in PCML:
         * http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/com.ibm.etools.iseries.webtools.doc/ref/rdtcattr.htm
         * 
         * For "int" values, length is the number of bytes; precision represents the number of bits. (Can be ignored here)
         * For zoned and packed values, length is the maximum number of digits; precision represents the maximum decimal places.
         * 
         */
        $length = (isset($attrs['length'])) ? (string) $attrs['length'] : '';
        $precision = (isset($attrs['precision'])) ? (string) $attrs['precision'] : '';

        $passBy = ''; // default of blank will become 'ref'/Reference in XMLSERVICE. Blank is fine here.
        if (isset($attrs['passby']) && ($attrs['passby'] == 'value')) {
            $passBy = 'val'; // rare. PCML calls it 'value'. XMLSERVICE calls it 'val'.
        }
        
        // find new toolkit equivalent of PCML data type
        if (isset($this->_pcmlTypeMap[$type])) {
            // a simple type mapping
            $newType = (string) $this->_pcmlTypeMap[$type];
        } elseif ($type == 'int') {
            // one of the integer types. Need to use length to determine which one.
            if ($length == '2') {
                $newType = '5i0'; // short ints have two bytes
            } elseif ($length == '4') {
                $newType = '10i0'; // normal ints have four bytes
            } else {
                $newType = ''; // no match
            } //(length == 2, et al.)
        } else {
            $newType = '';
        }
            
        $newInout = (isset($this->_pcmlInoutMap[$usage])) ? (string) $this->_pcmlInoutMap[$usage] : '';

        // @todo correct all this isArray business. 
        // Can we manage without isArray? 
        // well, it's already handled by toolkit....try and see, though.
        // poss. eliminate extra object levels, at least?
        
        if ($count > 1) {
            $isArray = true;
        } else {
            // no need for any dummy value.Could be 'init' from above, or leave the default.
            $isArray = false;
        }

        // @todo I think simply add 'counterLabel' and 'countedLabel'. 
        // count
        $newCount = 0; // initialize
        // @todo deal with this. Really need a better way to find the counter data elements.
        // Allow a countref, too, in PCML??? Maybe! Count will be the dim (max) and countref is the actual name.
        // Some customers have done it wrong. Instead of specifying a field as count, gave max count.
        // "count can be a number where number defines a fixed, never-changing number of elements in a sized array.
        // OR a data-name where data-name defines the name of a <data> element within the PCML document that will contain, at runtime, the number of elements in the array. The data-name specified can be a fully qualified name or a name that is relative to the current element. In either case, the name must reference a <data> element that is defined with type="int". See Resolving Relative Names for more information about how relative names are resolved.
        // about finding the element: http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzahh%2Flengthprecisionrelative.htm
        // Names are resolved by seeing if the name can be resolved as a child or descendent of the tag containing the current tag. If the name cannot be resolved at this level, the search continues with the next highest containing tag. This resolution must eventually result in a match of a tag that is contained by either the <pcml> tag or the <rfml> tag, in which case the name is considered to be an absolute name, not a relative name.""
        // Let's simply use $countersAndCounted. If necessary, pre-process PCML to create $countersAndCounted.
        if (is_numeric($count) && ($count > 0)) {
            $newCount = $count;
        }
        
        // $subElements are if this is a struct.
        if (count($subElements)) {
            $dataValue = $subElements;
        }

        $param = new ProgramParameter(sprintf($newType, $length, $precision), $newInout, '', $name, $dataValue, 'off', $newCount, $passBy, $isArray);

        if ($this->_countersAndCounted) {
            // some counters were configured
            // counter item reference was specified.
            if (isset($this->_countersAndCounted[$name])) {
                $param->setParamLabelCounter($name);
            }
            
            // counted item reference was specified as value in array.
            // look for value ($name). if found, counter is key.
           if ($counter = array_search($name, $this->_countersAndCounted)) {
                $param->setParamLabelCounted($counter);
            }
        }
        
        return $param;
    }
264670
private function createValue(array $dataRow, ElementtypeStructure $elementtypeStructure)
    {
        $field = $this->fieldRegistry->getField($dataRow['type']);
        $content = $field->unserialize($dataRow['content']);

        $name = $dataRow['name'];
        $node = $elementtypeStructure->getNode($dataRow['ds_id']);
        if ($node) {
            $name = $node->getName();
        }

        return new ElementStructureValue(
            $dataRow['id'],
            $dataRow['ds_id'],
            $dataRow['language'],
            $dataRow['type'],
            $field->getDataType(),
            $name,
            $content,
            $dataRow['options'] ? json_decode($dataRow['options'], true) : null
        );
    }
74028
public static function parseResponseIfXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $i = 0;
        $expression = null;
        $responseRules = array();
        foreach($xml->children() as $child){
            if($i){
                $name = $child->getName();
                $methodName = 'parse'.ucfirst($name).'Xml';
                if(method_exists(__CLASS__, $methodName)){
                    $responseRules[] = self::$methodName($child);
                } else{
                    $responseRules[] = self::parseResponseRuleXml($child);
                }
            }else{
                //the first child is the expression
                $expression = self::parseExpressionXml($child);
            }
            $i++;
        }
        $returnValue['expression'] = $expression;
        $returnValue['responseRules'] = $responseRules;
        return $returnValue;
    }
602942
public function createElementVersion(Element $element, ElementStructure $elementStructure = null, $triggerLanguage, $userId, $comment = null)
    {
        $oldElementVersion = $this->findLatestElementVersion($element);

        $elementSource = $this->findElementSource($element->getElementtypeId());

        $elementVersion = new ElementVersion();
        $elementVersion
            ->setId(null)
            ->setElement($element)
            ->setElementSource($elementSource)
            ->setVersion($oldElementVersion->getVersion() + 1)
            ->setCreateUserId($userId)
            ->setCreatedAt(new \DateTime())
            ->setComment($comment)
            ->setTriggerLanguage($triggerLanguage);

        $element->setLatestVersion($elementVersion->getVersion());

        $this->elementManager->updateElement($element, false);

        if ($elementStructure) {
            $this->fixElementVersion($elementStructure, $elementVersion);
            $this->elementStructureManager->updateElementStructure($elementStructure, false);
        }

        $this->fieldMapper->apply($elementVersion, $elementStructure, $elementStructure->getLanguages());

        $this->elementVersionManager->updateElementVersion($elementVersion, true);

        $this->elementHistoryManager->insert(
            ElementHistoryManagerInterface::ACTION_CREATE_ELEMENT_VERSION,
            $element->getEid(),
            $userId,
            null,
            null,
            $elementVersion->getVersion(),
            $triggerLanguage
        );

        return $elementVersion;
    }
263926
public function toXmlElement(SimpleXMLElement $parentElement = null)
    {
        if ($parentElement === null) {
            throw new UserMessageException(t('The sitemap XML page should not be the first element.'));
        }
        $result = $parentElement->addChild('url');
        $result->addChild('loc', (string) $this->getUrl());
        $lastModifiedAt = $this->getLastModifiedAt();
        if ($lastModifiedAt !== null) {
            $result->addChild('lastmod', $lastModifiedAt->format(DateTime::ATOM));
        }
        $changeFrequency = $this->getChangeFrequency();
        if ($changeFrequency !== '') {
            $result->addChild('changefreq', $changeFrequency);
        }
        $priority = $this->getPriority();
        if ($priority !== '') {
            $result->addChild('priority', $priority);
        }
        foreach ($this->getAlternativeLanguages() as $alternativeLanguage) {
            $alternativeLanguage->toXmlElement($result);
        }

        return $result;
    }
1316252
public function xml(): ?SimpleXMLElement
    {
        return simplexml_load_string(
            utf8_encode($this->response->getBody()->getContents()),
            'SimpleXMLElement',
            LIBXML_NOCDATA | LIBXML_NOBLANKS
        );
    }
1316113
public static function buildResponseRule( SimpleXMLElement $data)
    {
        $returnValue = null;

	    switch ($data->getName()) {
			case 'exitResponse' : $returnValue = new ExitResponse();
				break;
			case 'setOutcomeValue' :
				$identifier = (string)$data['identifier'];
				$children = array();
				foreach ($data->children() as $child){
					$children[] = $child;
				}
				$expression = ExpressionParserFactory::build(array_shift($children));
				$returnValue = new SetOutcomeVariable($identifier, $expression);
				break;
			case 'responseCondition' :
				$returnValue = self::buildResponseCondition($data);
				break;
			default :
				throw new ParsingException('unknwown element '.$data->getName().' in ResponseProcessing');
		}

        return $returnValue;
    }
1187134
private static function createTypeElement(\DOMDocument $document, $parentElement = null, $type)
    {
        if ($parentElement->parentNode === null) {
            $typeElement = $document->createElementNS(
                'https://github.com/RhubarbPHP/Rhubarb/blob/master/docs/simple-xml-transcoder.md',
                self::XMLNS . ':' . $type
            );
            $parentElement->appendChild($typeElement);
        } else {
            $parentElement->setAttribute(self::XMLNS . ':' . self::ATTR_TYPE, $type);
            $typeElement = $parentElement;
        }

        return $typeElement;
    }
1000668
public static function toDOM(BaseElement $element): \DOMDocument
    {
        $doc = new \DOMDocument('1.0', 'utf-8');
        $doc->appendChild($element->toDOM($doc));
        return $doc;
    }
459079
def createElement(self, token):
        """"""
        name = token["name"]
        namespace = token.get("namespace", self.defaultNamespace)
        element = self.elementClass(name, namespace)
        element.attributes = token["data"]
        return element
471937
private static function deserializePlayReadyContentKey($xmlElement)
    {
        $type = $xmlElement->attributes(Resources::XSI_XML_NAMESPACE)->type;

        if ($type == 'ContentEncryptionKeyFromHeader') {
            return new ContentEncryptionKeyFromHeader();
        }

        if ($type == 'ContentEncryptionKeyFromKeyIdentifier') {
            return new ContentEncryptionKeyFromKeyIdentifier($xmlElement->KeyIdentifier);
        }

        throw new \RuntimeException("Unknown PlayReadyContentKey type={$type}");
    }
647641
public function pcmlToArray(\SimpleXMLElement $xmlObj)
    {
        $dataDescription = array();

        // put structs in its own variable that can be accessed independently.
        $this->_pcmlStructs = $xmlObj->xpath('struct');

        // looking for ->data and ->struct.
        $dataElements = $xmlObj->xpath('program/data');

        if ($dataElements) {
            foreach ($dataElements as $dataElement) {

                $dataDescription[] = $this->singlePcmlToArray($dataElement);
            }
        }

        return $dataDescription;
    }
555447
public function _getElementHtml(
        \Magento\Framework\Data\Form\Element\AbstractElement $element
    ) {
        // Use Varien text element as a basis
        $input = $this->text;

        // Set data from config element on Varien text element
        $input->setForm($element->getForm())
            ->setElement($element)
            ->setValue($element->getValue())
            ->setHtmlId($element->getHtmlId())
            ->setClass('ddg-colpicker')
            ->setName($element->getName());

        // Inject updated Varien text element HTML in our current HTML
        $html = $input->getHtml();

        return $html;
    }
539487
private function getFormatFor($dateElement)
    {
        if ($this->dateTimeFormat->keyExists($dateElement)) {
            return $this->dateTimeFormat->key($dateElement);
        }

        return self::$formatters->key($dateElement)->first();
    }
499842
static function processElementTransformationChild( $useComments, $php, $tpl, &$node,
                                                $elementTree, $elementList, &$resourceData )
    {
        $count = is_countable( $elementList ) ? count( $elementList ) : 0;
        $lastElement = null;
        $newElementList = array();
        for ( $i = 0; $i < $count; ++$i )
        {
            $element =& $elementList[$i];
            $elementType = $element[0];
            if ( $elementType == eZTemplate::TYPE_OPERATOR )
            {
                $operatorName = $element[1][0];
                $operatorParameters = array_slice( $element[1], 1 );
                if ( !isset( $tpl->Operators[$operatorName] ) )
                    return false;

                if ( is_array( $tpl->Operators[$operatorName] ) )
                {
                    $tpl->loadAndRegisterOperators( $tpl->Operators[$operatorName] );
                }
                $operatorObject =& $tpl->Operators[$operatorName];
                if ( is_object( $operatorObject ) )
                {
                    $hasTransformationSupport = false;
                    $transformParameters = false;
                    $inputAsParameter = false;
                    $knownType = 'static';
                    if ( method_exists( $operatorObject, 'operatorTemplateHints' ) )
                    {
                        $hints = $operatorObject->operatorTemplateHints();
                        if ( isset( $hints[$operatorName] ) and
                             isset( $hints[$operatorName]['element-transformation'] ) and
                             $hints[$operatorName]['element-transformation'] )
                        {
                            $hasTransformationSupport = true;
                        }

                        if ( $hasTransformationSupport  and
                             isset( $hints[$operatorName]['element-transformation-func'] ) )
                        {
                            $transformationMethod = $hints[$operatorName]['element-transformation-func'];
                        }
                        else
                        {
                            $transformationMethod = 'templateElementTransformation';
                        }

                        if ( isset( $hints[$operatorName] ) and
                             isset( $hints[$operatorName]['transform-parameters'] ) )
                        {
                            $transformParameters = $hints[$operatorName]['transform-parameters'];
                        }

                        if ( isset( $hints[$operatorName] ) and
                             isset( $hints[$operatorName]['input-as-parameter'] ) )
                        {
                            $inputAsParameter = $hints[$operatorName]['input-as-parameter'];
                        }

                        if ( isset( $hints[$operatorName]['output'] ) and !$hints[$operatorName]['output'] )
                        {
                            $knownType = 'null';
                        }
                        else if ( isset( $hints[$operatorName]['output-type'] ) )
                        {
                            $knownType = $hints[$operatorName]['output-type'];
                        }
                    }
                    if ( $hasTransformationSupport and
                         method_exists( $operatorObject, $transformationMethod ) )
                    {
                        $resetNewElementList = false;
                        if ( $transformParameters )
                        {
                            $newParameters = array();
                            if ( $inputAsParameter )
                            {
                                $newParameterElements = eZTemplateCompiler::processElementTransformationChild( $useComments, $php, $tpl, $node,
                                                                                                               $elementTree, $newElementList, $resourceData );
                                if ( count( $newParameterElements ) > 0 or
                                     $inputAsParameter === 'always' )
                                {
                                    $newParameters[] = $newParameterElements;
                                    $resetNewElementList = true;
                                }
                            }

                            foreach ( $operatorParameters as $operatorParameter )
                            {
                                $newParameterElements = eZTemplateCompiler::processElementTransformationChild( $useComments, $php, $tpl, $node,
                                                                                                               $elementTree, $operatorParameter, $resourceData );
                                if ( !$newParameterElements )
                                    $newParameters[] = $operatorParameter;
                                else
                                    $newParameters[] = $newParameterElements;
                            }
                            $operatorParameters = $newParameters;
                        }

                        $newElements = $operatorObject->$transformationMethod( $operatorName, $node, $tpl, $resourceData,
                                                                               $element, $lastElement, $elementList, $elementTree,
                                                                               $operatorParameters );
                        if ( is_array( $newElements ) )
                        {
                            if ( $resetNewElementList )
                            {
                                $newElementList = $newElements;
                            }
                            else
                            {
                                $newElementList = array_merge( $newElementList, $newElements );
                            }
                        }
                        else
                        {
                            $newElementList[] = $element;
                        }
                    }
                    else
                    {
                        $newElementList[] = $element;
                    }
                }
                else if ( $resourceData['test-compile'] )
                {
                    $tpl->warning( '', "Operator '$operatorName' is not registered." );
                }
            }
            else
            {
                $newElementList[] = $element;
            }
            $lastElement = $element;
        }
        return $newElementList;
    }
1366217
private static function deserializeAlternateVerificationKeys($xmlElement)
    {
        $result = [];

        foreach ($xmlElement->children() as $child) {
            $result[] = self::deserializeTokenVerificationKey($child);
        }

        return $result;
    }
463316
protected function locateDataObject(SimpleXMLElement $element, CNabuDataObject $data_parent = null) : bool
    {
        $retval = false;
        
        if (isset($element['GUID'])) {
            $guid = (string)$element['GUID'];
            if (!($this->nb_data_object instanceof CNabuSiteTargetLanguageList)) {
                $this->nb_data_object = CNabuSiteTargetLanguageList::findByHash($guid);
            } else {
                $this->nb_data_object = null;
            }
        
            if (!($this->nb_data_object instanceof CNabuSiteTargetLanguageList)) {
                $this->nb_data_object = new CNabuSiteTargetLanguageList();
                $this->nb_data_object->setHash($guid);
            }
            $retval = true;
        }
        
        return $retval;
    }