Append an integer index array of values to this XML document

@param array $data
@param string $elementName
@param string|null $nsPrefix
@param string|null $nsUri
@return bool
2182
public function appendList(array $data, $elementName, $nsPrefix = null, $nsUri = null)
    {
        if (null === $nsPrefix) {
            foreach ($data as $value) {
                $this->writeElement($elementName, $value);
            }
        } else {
            foreach ($data as $value) {
                $this->writeElementNS($nsPrefix, $elementName, $nsUri, $value);
            }
        }

        return true;
    }
86560
public function xml(array $data, $charset = null)
    {
        $dom = new DOMDocument('1.0', $charset === null ? Yii::$app->charset : $charset);
        $root = new DOMElement('xml');
        $dom->appendChild($root);
        $this->buildXml($root, $data);
        $xml = $dom->saveXML();
        return trim(substr($xml, strpos($xml, '?>') + 2));
    }
326107
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
    {
        $value = $data['value'];

        if ($encode === true) {
            $value = General::sanitize($value);
        } else {
            if (!General::validateXML($data['value'], $errors, false, new XsltProcess)) {
                $value = html_entity_decode($data['value'], ENT_QUOTES, 'UTF-8');
                $value = $this->__replaceAmpersands($value);

                if (!General::validateXML($value, $errors, false, new XsltProcess)) {
                    $value = General::sanitize($data['value']);
                }
            }
        }

        $wrapper->appendChild(
            new XMLElement($this->get('element_name'), $value, array('handle' => $data['handle']))
        );
    }
819098
public function pushElement($listUuid, $elementUuid, array $data = [])
    {
        $newElement = new ListElement(
            new ListElementUuid($elementUuid),
            $data
        );

        return $this->repository->pushElement($listUuid, $newElement);
    }
639058
protected function addAttributes($element, $data)
    {
        foreach ($data as $attrKey => $attrVal) {
            $element->setAttribute($attrKey, $attrVal);
        }
    }
400176
protected function generateArrayValue(\XmlWriter $writer, $value, $key, $elementName = 'value')
    {
        if ($this->isNumericArray($value)) {
            $this->generateListArray($writer, $value, $key, $elementName);
        } else {
            $this->generateHashArray($writer, $value, $key, $elementName);
        }
    }
942122
protected static function saveXml( $fileName, $data )
	{
		$root	= new XML_DOM_Node( "configuration" );
		foreach( $data as $sectionName => $sectionData )
		{
			$sectionNode	= new XML_DOM_Node( "section" );
			$sectionNode->setAttribute( 'name', $sectionName );			
			foreach( $sectionData as $pair )
			{
				$comment	= isset( $pair['comment'] ) ? $pair['comment'] : NULL;
				$valueNode	= new XML_DOM_Node( "value", $pair['value'] );
				$valueNode->setAttribute( 'type', $pair['type'] );
				$valueNode->setAttribute( 'name', $pair['key'] );
				if( isset( $pair['comment'] ) )
					$valueNode->setAttribute( 'comment', $comment );
				$sectionNode->addChild( $valueNode );
			}
			$root->addChild( $sectionNode );
		}
		return XML_DOM_FileWriter::save( $fileName, $root );
	}
75375
protected function writeArrayItem(\XMLWriter $xmlWriter, array $itemArray, $elementName)
    {
        Validate::isString($elementName, 'elementName');

        foreach ($itemArray as $itemInstance) {
            $xmlWriter->startElementNS(
                'atom',
                $elementName,
                Resources::ATOM_NAMESPACE
            );
            $itemInstance->writeInnerXml($xmlWriter);
            $xmlWriter->endElement();
        }
    }
483470
protected function prepareElementName(&$elementName)
    {
        $tempElementName = explode('_', $elementName);
        $elementName = isset($tempElementName[0]) && is_numeric($tempElementName[0])
            ? $tempElementName[1]
            : $elementName;
    }
171281
static public function encodeElement($data, $root='xml')
    {
        if (!$data) {
            $data = [];
        } elseif (is_string($data)) {
            return $data;
        }
        
        assert('is_array($data) || $data instanceof Traversable');
        
        $output = '';
        if ($data) foreach ($data as $key => $val) {
            if (is_numeric($key)) {
                // Convert the key to a valid string
                $key = "unknownNode_". (string) $key;
            }
            
            // Delete any char not allowed in XML element names
            $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
            
            if (is_array($val)) {
                $output .= '<' . $key . '>';
                $output .= self::encodeElement($val, null);
                $output .= '</' . $key . '>';
            } else {
                
                if (is_numeric($val)){
                    $output .= "<".$key.">".$val."</".$key.">";
                }else{
                    $val = str_replace('&', '&amp;', print_r($val, true));
                    $output .= "<". $key . "><![CDATA[".$val."]]></" . $key . ">";
                }
            }
        }
        if ($output) {
            $output = PHP_EOL . $output . PHP_EOL;
        }
        if ($root) {
            $output = "<?xml version='1.0' encoding='utf-8'?>" . PHP_EOL . "<$root>$output</$root>";
        }
        
        return $output;
    }
664931
public void addDataElement(String elemName, String content, String attrName, String attrValue) {
        AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute("", attrName, "", "CDATA", attrValue);
        writeDataElement(elemName, attrs, content);
    }
1137692
public function writeElement(
            string $elementName,
            array $attributes = [],
            string $cdata     = null
    ): XmlStreamWriter {
        return $this->append(
                function(\DOMNode $parent) use ($elementName, $attributes, $cdata)
                {
                    $element = $this->doc->createElement($elementName);
                    foreach ($attributes as $name => $value) {
                        $element->setAttribute($name, $this->encode($value));
                    }

                    if (null !== $cdata) {
                        $element->appendChild($this->doc->createTextNode($this->encode($cdata)));
                    }

                    $parent->appendChild($element);
                },
                'element: "' . $elementName . '"'
        );
    }
839306
protected function renderElement(HTMLElement $element, $data = [])
    {
        // Check for actions
        $actions = $data['actions'];

        // Check for "delete" action
        if (isset($actions['delete']) && $actions['delete']) {
            $this->getHTMLHandler()->remove($element);

            return $this;
        }

        // Add/Append all attributes
        foreach ($data['attributes'] as $name => $value) {
            // Evaluate given value using scss syntax (replace & with existing value, for class attributes only)
            $existingValue = $this->getHTMLHandler()->attr($element, $name);
            $value = is_string($value) && $name == 'class' ? str_replace('&', $existingValue, $value) : $value;

            // Set new value
            $this->getHTMLHandler()->attr($element, $name, $value);
        }

        // Add/Append all data attributes
        foreach ($data['data'] as $name => $value) {
            $this->getHTMLHandler()->data($element, $name, $value);
        }

        // Apply style attributes
        foreach ($data['style'] as $name => $value) {
            $this->getHTMLHandler()->style($element, $name, $value);
        }

        // Check for node value
        $nodeValue = $data['nodeValue'];
        if (!is_null($nodeValue)) {
            $this->getHTMLHandler()->nodeValue($element, $nodeValue);
        }

        // Check for inner html
        $innerHTML = $data['innerHTML'];
        if (!is_null($innerHTML)) {
            $this->getHTMLHandler()->innerHTML($element, $innerHTML);
        }

        // Append children
        $appendElements = $actions['append'] ?: [];
        $appendElements = is_array($appendElements) ? $appendElements : [$appendElements];
        foreach ($appendElements as $appendElement) {
            $this->getHTMLHandler()->append($element, $appendElement);
        }

        // Prepend children
        $prependElements = $actions['prepend'] ?: [];
        $prependElements = is_array($prependElements) ? $prependElements : [$prependElements];
        foreach ($prependElements as $prependElement) {
            $this->getHTMLHandler()->prepend($element, $prependElement);
        }

        // Render tag-specific parameters
        $this->renderSelect($element, $data['select']);
        $this->renderForm($element, $data['form']);

        return $this;
    }
472479
private function addElement($name, $parent = false, $ns = false)
    {
        if ($ns) {
            $el = $this->doc->createElementNS($ns, $name);
        } else {
            $el = $this->doc->createElement($name);
        }
        if ($parent) {
            $parent->appendChild($el);
        }

        return $el;
    }
314133
private function buildXml($data, \DOMDocument $doc, \DOMNode $parentNode = null)
    {
        if (is_array($data)) {
            foreach ($data as $elementName => $element) {
                if (is_int($elementName)) {
                    $elementName = 'item';
                }

                $newElement = $doc->createElement($elementName);

                if ($parentNode) {
                    $parentNode->appendChild($newElement);
                } else {
                    $doc->appendChild($newElement);
                }

                $this->buildXml($element, $doc, $newElement);
            }
        } else {
            $parentNode->nodeValue = $data;
        }
    }
506675
protected function _arrayToXml($data, Xml $xml, $addCdata, $parent)
    {
        foreach ($data as $key => $value) {
            $key        = str_replace(' ', '_', $key);
            $attributes = [];
            $data       = '';

            if (is_object($value)) {
                try {
                    $data = Serializer::serialize($value);
                } catch (ExceptionInterface $exception) {
                    $this->_addException($exception);
                }

                $value = [
                    '@attributes' => ['serialized_object' => true],
                    $data
                ];
            }

            try {
                $isArray = is_array($value);

                if ($isArray && array_key_exists('@attributes', $value)) {
                    $attributes = $value['@attributes'];
                    unset ($value['@attributes']);
                }

                if ($isArray) {
                    $parent = $this->_convertArrayDataToXml(
                        $value,
                        $addCdata,
                        $xml,
                        $key,
                        $parent,
                        $attributes
                    );
                    continue;
                }

                $element = $this->_appendDataToNode($addCdata, $xml, $key, $value);
                $parent->appendChild($element);

            } catch (DOMException $exception) {
                $this->_addException($exception);
            }
        }

        return $xml;
    }
1320391
protected function addTrackSelect(array &$elements, $data, $elementId = 'gto_id_track')
    {
        // Store for use in addFillerSelect
        $this->trackFieldId = $elementId;
        
        $orgs   = $this->currentUser->getRespondentOrganizations();
        $tracks = $this->util->getTrackData()->getTracksForOrgs($orgs);

        if (count($tracks) > 1) {
            $elements[$elementId] = $this->_createSelectElement($elementId, $tracks, $this->_('(select a track)'));
            $elements[$elementId]->setAttrib('onchange', 'this.form.submit();');
        }
    }