Format part of the data
@param mixed $data The data to be serialised into xml
@param string|null $nodeName The node currently being worked on
@return string
515066
public function partialFormat($data, $nodeName = null)
    {
        if (!$nodeName) {
            $nodeName = $this->getNodeName($data);
        }
        $data = $this->parseData($data);

        if (is_scalar($data)) {
            return "<$nodeName>" . $this->parseScalarData($data) . "</$nodeName>";
        }
        return "<$nodeName>".$this->parseNonScalarData($data, $nodeName)."</$nodeName>";
    }
1288348
public static function parse($data)
    {
        $xml = null;
        if ($xml = simplexml_load_string($data)) {
            $xml = (array)$xml;
        }
        return $xml;
    }
1014028
protected function createAndReturnNewFirstEntity($data, $entityName)
    {
        if (is_array($data)) {
            $entity = $this->getFirstEntityByName($entityName);
            return $this->mapAttributesFromSecondEntityToFirstEntityAndReturnEntity($data, $entity);
        }

        return null;
    }
555773
protected function formatStringCellValue($node)
    {
        $pNodeValues = [];
        $pNodes = $node->getElementsByTagName(self::XML_NODE_P);

        foreach ($pNodes as $pNode) {
            $currentPValue = '';

            foreach ($pNode->childNodes as $childNode) {
                if ($childNode instanceof \DOMText) {
                    $currentPValue .= $childNode->nodeValue;
                } else if ($childNode->nodeName === self::XML_NODE_S) {
                    $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
                    $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1;
                    $currentPValue .= str_repeat(' ', $numSpaces);
                } else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
                    $currentPValue .= $childNode->nodeValue;
                }
            }

            $pNodeValues[] = $currentPValue;
        }

        $escapedCellValue = implode("\n", $pNodeValues);
        $cellValue = $this->escaper->unescape($escapedCellValue);
        return $cellValue;
    }
449470
public function ReturnFileContents($nodeName) {
        if (file_exists($this->filePath)) {

            $xml = new \DOMDocument;
            $xml->load($this->filePath);

            return $xml->getElementsByTagName($nodeName);
        }
        return false;
    }
952029
protected function parseNonScalarData($data, $fallbackName = null)
    {
        $xml = '';
        if (!$fallbackName) {
            $fallbackName = $this->defaultNodeName;
        }
        foreach ($data as $property => $value) {
            // Clear non-alphanumeric characters
            $property = preg_replace('/\W/', '', $property);

            // If numeric we'll stick a character in front of it, a bit hack but should be valid
            if (is_numeric($property)) {
                $property = $fallbackName;
            }
            $xml .= $this->partialFormat($value, $property);
        }
        return $xml;

    }
411698
public static function toXML($data, $rootNodeName = 'entity', &$xml=null )
    {

        // turn off compatibility mode
        if ( ini_get('zend.ze1_compatibility_mode') == 1 ) ini_set ( 'zend.ze1_compatibility_mode', 0 );
        if ( is_null( $xml ) ) //$xml = simplexml_load_string( "" );
            $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");

        // loop through the data passed in.
        foreach( $data as $key => $value ) {
            $numeric = false;
            // no numeric keys in our xml please!
            if ( is_numeric( $key ) ) {
                $numeric = 1;
                $key = $rootNodeName;
            }
            // delete any char not allowed in XML element names
            $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
            // if there is another array found recrusively call this function
            if ( is_array( $value ) ) {
                $node = self::isAssoc( $value ) || $numeric ? $xml->addChild( $key ) : $xml;
                // recrusive call.
                if ($numeric) $key = 'anon';
                self::toXml( $value, $key, $node );
            } else {
                // add single node.
                $value = Html::encode($value);
                $xml->addChild($key, $value);
            }
        }
        // pass back as XML
        return $xml->asXML();
    }
542332
protected static function arrayFormat(array $data, $name)
    {
        $format = "\t'$name' => [\n";

        if (count($data) > 0) {
            foreach ($data as $key => $value) {
                $format .= "\t\t'$key' => $value::class , \n";
            }
        } else {
            $format .= "\t\t//\n";
        }

        $format .= "\t],\n\n";

        return $format;
    }
109506
public function xssClean($data)
    {
        // If its empty there is no point cleaning it :\
        if (empty($data)) {
            return $data;
        }

        // Recursive loop for arrays
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = $this->xssClean($data);
            }

            return $data;
        }

        // Fix &entity\n;
        $data = $this->fixEntity($data);

        // Remove any attribute starting with "on" or xmlns
        $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);

        // Remove javascript: and vbscript: protocols
        $data = $this->removeJavaScriptProtocols($data);

        $data = $this->removeVbScriptProtocols($data);

        $data = preg_replace(
            '#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u',
            '$1=$2nomozbinding...',
            $data
        );

        // Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
        $data = $this->fixIe($data);

        // Remove namespaces elements (we do not need them)
        $data = $this->removeNameSpaceElements($data);

        $data = preg_replace($this->sqlReplace, '', $data);

        do {
            // Remove really unwanted tags
            $old_data = $data;
            $data = preg_replace(
                '#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l
                (?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i',
                '',
                $data
            );
        } while ($old_data !== $data);

        return htmlentities($data);
    }
456479
public function serializeData($data) {
		if(is_array($data)) {
			ksort($data);
			$return = '';
			foreach($data as $key => $value) {
				if(is_numeric($key)) {
					$return .= $this->serializeData($value);
				} else {
					$return .= $key . $this->serializeData($value);
				}
			}
			return $return;
		} else {
			return (string)$data;
		}
	}
659604
protected function formatInlineStringCellValue($node)
    {
        // inline strings are formatted this way:
        // <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
        $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
        $cellValue = $this->escaper->unescape($tNode->nodeValue);
        return $cellValue;
    }
883002
public function makeData(Data $data): ?DataObjectFormat
    {
        if (!$data->isInstanceOf(Data::class)) {
            return null;
        }

        return DataObjectFormat::make($data);
    }
80889
public static function data_to_xml($data) {
        $xml = '';
        foreach ($data as $key => $val) {
            is_numeric($key) && $key = "item id=\"$key\"";
            $xml    .=  "<$key>";
            $xml    .=  ( is_array($val) || is_object($val)) ? self::data_to_xml($val)  : self::xmlSafeStr($val);
            list($key, ) = explode(' ', $key);
            $xml    .=  "</$key>";
        }
        return $xml;
    }
551706
public function formatData(array $data, $fieldset = null)
    {
        $schema = $this->schema;

        if (!is_null($fieldset)) {
            $schema = $fieldset;
        }

        $fields = $schema->getFields();
        $table = $schema->getName();

        foreach ($fields as $field) {
            $name = $table . '_' . $field['name'];
            //if there's no data
            if (!isset($data[$name])) {
                //no need to format
                continue;
            }

            if ($data[$name] === 'NOW()') {
                $data[$name] = date('Y-m-d H:i:s');
            }

            if ($field['field']['type'] === 'latlng' && is_array($data[$name])) {
                if (!is_numeric($data[$name][0])) {
                    $data[$name][0] = 0;
                }

                if (!is_numeric($data[$name][1])) {
                    $data[$name][1] = 0;
                }

                $data[$name][0] = sprintf('%.8F', $data[$name][0]);
                $data[$name][1] = sprintf('%.8F', $data[$name][1]);
            }

            if ($field['field']['type'] === 'fieldset') {
                //case for multiple
                if (isset($field['field']['attributes']['data-multiple'])
                    && !$field['field']['attributes']['data-multiple']
                ) {
                    //format single data
                    $data[$name] = $this->formatData(
                        $data[$name],
                        Fieldset::i($field['field']['parameters']),
                        false
                    );
                } else {
                    //format each data
                    foreach($data[$name] as $index => $row) {

                        $data[$name][$index] = $this->formatData(
                            $row,
                            Fieldset::i($field['field']['parameters']),
                            false
                        );
                    }
                }
            }

            switch ($field['field']['type']) {
                case 'file':
                case 'image':
                    //upload files
                    $data[$name] = $this->upload($data[$name]);
                    break;
                case 'filelist':
                case 'imagelist':
                    //upload files
                    $data[$name] = $this->upload($data[$name]);

                    //we should not encode if fieldset
                    if (is_null($fieldset)) {
                        $data[$name] = json_encode($data[$name]);
                    }
                    break;
                case 'tag':
                case 'textlist':
                case 'textarealist':
                case 'wysiwyglist':
                case 'meta':
                case 'checkboxes':
                case 'multirange':
                case 'multiselect':
                case 'table':
                case 'latlng':
                case 'fieldset':
                    //if it's an array already
                    if((is_array($data[$name]) || is_object($data[$name])) && is_null($fieldset)) {
                        $data[$name] = json_encode($data[$name]);

                        //if it's a json string
                        if(strpos($data[$name], '{') === 0
                            || strpos($data[$name], '[') === 0
                        )
                        {
                            break;
                        }

                        //it can only be comma separated
                        $data[$name] = explode(',', $data[$name]);
                        $data[$name] = json_encode($data[$name]);
                    }

                    break;
                case 'created':
                case 'updated':
                case 'datetime':
                    if (trim($data[$name])) {
                        $data[$name] = date('Y-m-d H:i:s', strtotime($data[$name]));
                    } else {
                        $data[$name] = null;
                    }

                    break;
                case 'date':
                    if (trim($data[$name])) {
                        $data[$name] = date('Y-m-d', strtotime($data[$name]));
                    } else {
                        $data[$name] = null;
                    }

                    break;
                case 'time':
                    if (trim($data[$name])) {
                        $data[$name] = date('H:i:s', strtotime($data[$name]));
                    } else {
                        $data[$name] = null;
                    }

                    break;
                case 'password':
                    $data[$name] = password_hash($data[$name], PASSWORD_DEFAULT);
                    break;
                case 'md5':
                    $data[$name] = md5($data[$name]);
                    break;
                case 'sha1':
                    $data[$name] = sha1($data[$name]);
                    break;
                case 'active':
                case 'checkbox':
                    if ($data[$name]) {
                        $data[$name] = 1;
                    } else {
                        $data[$name] = 0;
                    }
                    break;
                case 'uuid':
                case 'token':
                    $data[$name] = md5(uniqid());
                    break;
                case 'number':
                case 'small':
                    if (!$data[$name]) {
                        $data[$name] = null;
                    }
                    break;
                case 'textarea':
                case 'wysiwyg':
                case 'code':
                    //fix for textarea in textarea
                    $data[$name] = str_replace('<\/textarea>', '</textarea>', $data[$name]);
                    break;
            }
        }

        return $data;
    }
624891
public function encode($data)
    {
        $result = '';
        foreach($data as $k => $v)
        {
            $result .= $k . '|' . serialize($v);
        }
        return $result;
    }
1349000
protected static function _createChild($data)
    {
        $data += [
            'dom' => null,
            'node' => null,
            'key' => null,
            'value' => null,
            'format' => null,
        ];

        $value = $data['value'];
        $dom = $data['dom'];
        $key = $data['key'];
        $format = $data['format'];
        $node = $data['node'];

        $childNS = $childValue = null;
        if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
            $value = call_user_func([$value, 'toArray']);
        }
        if (is_array($value)) {
            if (isset($value['@'])) {
                $childValue = (string)$value['@'];
                unset($value['@']);
            }
            if (isset($value['xmlns:'])) {
                $childNS = $value['xmlns:'];
                unset($value['xmlns:']);
            }
        } elseif (!empty($value) || $value === 0 || $value === '0') {
            $childValue = (string)$value;
        }

        $child = $dom->createElement($key);
        if ($childValue !== null) {
            $child->appendChild($dom->createTextNode($childValue));
        }
        if ($childNS) {
            $child->setAttribute('xmlns', $childNS);
        }

        static::_fromArray($dom, $child, $value, $format);
        $node->appendChild($child);
    }
906436
protected function _xmlToArray(DOMElement $data)
    {
        $temporaryData = [];

        /** @var $node DOMElement */
        foreach ($data->childNodes as $node) {
            $nodeName           = $this->_stringToIntegerKey($node->nodeName);
            $nodeData           = [];
            $unSerializedData   = [];

            if ($node->hasAttributes() && $node->getAttribute('serialized_object')) {
                try {
                    $unSerializedData = Serializer::unserialize($node->nodeValue);
                } catch (ExceptionInterface $exception) {
                    $this->_addException($exception);
                }

                $temporaryData[$nodeName] = $unSerializedData;
                continue;
            }

            if ($node->hasAttributes()) {
                foreach ($node->attributes as $key => $value) {
                    $nodeData['@attributes'][$key] = $value->nodeValue;
                }
            }

            if ($node->hasChildNodes()) {
                $childNodesData = [];

                /** @var $childNode DOMElement */
                foreach ($node->childNodes as $childNode) {
                    if ($childNode->nodeType === 1) {
                        $childNodesData = $this->_xmlToArray($node);
                    }
                }

                if (!empty($childNodesData)) {
                    $temporaryData[$nodeName] = $childNodesData;
                    continue;
                }
            }

            if (!empty($nodeData)) {
                $temporaryData[$nodeName] = array_merge(
                    [$node->nodeValue],
                    $nodeData
                );
            } else {
                $temporaryData[$nodeName] = $node->nodeValue;
            }
        }

        return $temporaryData;
    }