Load data from XML to the structure
@param array $xmlarr
@return bool
421730
public function arr2xmldb_structure($xmlarr) {

        global $CFG;

        $result = true;

        // Debug the structure
        // traverse_xmlize($xmlarr);                   //Debug
        // print_object ($GLOBALS['traverse_array']);  //Debug
        // $GLOBALS['traverse_array']="";              //Debug

        // Process structure attributes (path, comment and version)
        if (isset($xmlarr['XMLDB']['@']['PATH'])) {
            $this->path = trim($xmlarr['XMLDB']['@']['PATH']);
        } else {
            $this->errormsg = 'Missing PATH attribute';
            $this->debug($this->errormsg);
            $result = false;
        }
        // Normalize paths to compare them.
        $filepath = realpath($this->name); // File path comes in name.
        $filename = basename($filepath);
        $normalisedpath = $this->path;
        if ($CFG->admin !== 'admin') {
            $needle = 'admin/';
            if (strpos($this->path, $needle) === 0) {
                $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
            }
        }
        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
        if ($filepath !== $structurepath) {
            $relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
            $this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;
            $this->debug($this->errormsg);
            $result = false;
        }
        if (isset($xmlarr['XMLDB']['@']['VERSION'])) {
            $this->version = trim($xmlarr['XMLDB']['@']['VERSION']);
        } else {
            $this->errormsg = 'Missing VERSION attribute';
            $this->debug($this->errormsg);
            $result = false;
        }
        if (isset($xmlarr['XMLDB']['@']['COMMENT'])) {
            $this->comment = trim($xmlarr['XMLDB']['@']['COMMENT']);
        } else if (!empty($CFG->xmldbdisablecommentchecking)) {
            $this->comment = '';
        } else {
            $this->errormsg = 'Missing COMMENT attribute';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Iterate over tables
        if (isset($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'])) {
            foreach ($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'] as $xmltable) {
                if (!$result) { //Skip on error
                    continue;
                }
                $name = trim($xmltable['@']['NAME']);
                $table = new xmldb_table($name);
                $table->arr2xmldb_table($xmltable);
                $this->tables[] = $table;
                if (!$table->isLoaded()) {
                    $this->errormsg = 'Problem loading table ' . $name;
                    $this->debug($this->errormsg);
                    $result = false;
                }
            }
        } else {
            $this->errormsg = 'Missing TABLES section';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Perform some general checks over tables
        if ($result && $this->tables) {
            // Check tables names are ok (lowercase, a-z _-)
            if (!$this->checkNameValues($this->tables)) {
                $this->errormsg = 'Some TABLES name values are incorrect';
                $this->debug($this->errormsg);
                $result = false;
            }
            // Compute prev/next.
            $this->fixPrevNext($this->tables);
            // Order tables
            if ($result && !$this->orderTables($this->tables)) {
                $this->errormsg = 'Error ordering the tables';
                $this->debug($this->errormsg);
                $result = false;
            }
        }

        // Set some attributes
        if ($result) {
            $this->loaded = true;
        }
        $this->calculateHash();
        return $result;
    }
555097
public static function xml(array $arr) {
        parent::setContentType('application/xml');

        $simpleXML = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
        self::arrayToXML($arr, $simpleXML);

        return $simpleXML->asXML();
    }
414670
protected function loadDataModels()
    {
        $ads = array();
        $totalNbTables = 0;
        $this->log('Loading XML schema files...');
        // Get all matched files from schemaFilesets
        foreach ($this->schemaFilesets as $fs) {
            $ds = $fs->getDirectoryScanner($this->project);
            $srcDir = $fs->getDir($this->project);

            $dataModelFiles = $ds->getIncludedFiles();
            sort($dataModelFiles);

            $defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();

            // Make a transaction for each file
            foreach ($dataModelFiles as $dmFilename) {

                $this->log("Processing: " . $dmFilename, Project::MSG_VERBOSE);
                $xmlFile = new PhingFile($srcDir, $dmFilename);

                $dom = new DomDocument('1.0', 'UTF-8');
                $dom->load($xmlFile->getAbsolutePath());

                // modify schema to include any external schemas (and remove the external-schema nodes)
                $this->includeExternalSchemas($dom, $srcDir);

                // normalize (or transform) the XML document using XSLT
                if ($this->getGeneratorConfig()->getBuildProperty('schemaTransform') && $this->xslFile) {
                    $this->log("Transforming " . $dmFilename . " using stylesheet " . $this->xslFile->getPath(), Project::MSG_VERBOSE);
                    if (!class_exists('XSLTProcessor')) {
                        $this->log("Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.", Project::MSG_ERR);
                    } else {
                        // normalize the document using normalizer stylesheet
                        $xslDom = new DomDocument('1.0', 'UTF-8');
                        $xslDom->load($this->xslFile->getAbsolutePath());
                        $xsl = new XsltProcessor();
                        $xsl->importStyleSheet($xslDom);
                        $dom = $xsl->transformToDoc($dom);
                    }
                }

                // validate the XML document using XSD schema
                if ($this->validate && $this->xsdFile) {
                    $this->log("  Validating XML using schema " . $this->xsdFile->getPath(), Project::MSG_VERBOSE);
                    if (!$dom->schemaValidate($this->xsdFile->getAbsolutePath())) {
                        throw new EngineException("XML schema file (" . $xmlFile->getPath() . ") does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $this->getLocation());
                    }
                }

                $xmlParser = new XmlToAppData($defaultPlatform, $this->getTargetPackage(), $this->dbEncoding);
                $xmlParser->setGeneratorConfig($this->getGeneratorConfig());
                $ad = $xmlParser->parseString($dom->saveXML(), $xmlFile->getAbsolutePath());
                $nbTables = $ad->getDatabase(null, false)->countTables();
                $totalNbTables += $nbTables;
                $this->log(sprintf('  %d tables processed successfully', $nbTables), Project::MSG_VERBOSE);

                $ad->setName($dmFilename);
                $ads[] = $ad;
            }
            $this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
        }

        if (empty($ads)) {
            throw new BuildException("No schema files were found (matching your schema fileset definition).");
        }

        foreach ($ads as $ad) {
            // map schema filename with database name
            $this->dataModelDbMap[$ad->getName()] = $ad->getDatabase(null, false)->getName();
        }

        if (count($ads) > 1 && $this->packageObjectModel) {
            $ad = $this->joinDataModels($ads);
            $this->dataModels = array($ad);
        } else {
            $this->dataModels = $ads;
        }

        foreach ($this->dataModels as &$ad) {
            $ad->doFinalInitialization();
        }

        if ($this->validate) {
            foreach ($this->dataModels as $dataModel) {
                $validator = new PropelSchemaValidator($dataModel);
                if (!$validator->validate()) {
                    throw new EngineException(sprintf("The database schema contains errors:\n - %s", join("\n - ", $validator->getErrors())));
                }
            }
        }

        $this->dataModelsLoaded = true;
    }
891365
public function insertAll(array $dataArr) {
        $statement = new InsertAllStatement($dataArr);
        $statement->setStatementContext($this->statementContext);
        $sql = $statement->parse();

        $rowCount = $this->connection->execute($sql, $this->statementContext->getParameters());

        $this->clear();

        return $rowCount;
    }
442783
private function array2xml($arr, $level = 1)
    {
        $str = ($level == 1) ? "<?xml version=\"1.0\" encoding=\"" . Config::get('default_charset') . "\"?>\r\n<root>\r\n" : '';
        $space = str_repeat("\t", $level);
        foreach ($arr as $key => $val) {
            if (is_numeric($key)) {
                $key = 'item';
            }
            if (!is_array($val)) {
                if (is_string($val) && preg_match('/[&<>"\'\?]+/', $val)) {
                    $str .= $space . "<$key><![CDATA[" . $val . ']]>' . "</$key>\r\n";
                } else {
                    $str .= $space . "<$key>" . $val . "</$key>\r\n";
                }
            } else {
                $str .= $space . "<$key>\r\n" . self::array2xml($val, $level + 1) . $space . "</$key>\r\n";
            }
        }
        if ($level == 1) {
            $str .= '</root>';
        }
        return $str;
    }
1298889
public function load($uri)
    {
        $this->checkURI($uri);
        if (!file_exists($uri)) {
            //Do not fail, if file doesn't exist.
            return;
        }
        if (!@$this->dom->load($uri)) {
            throw new Klarna_XMLParseException($uri);
        }

        $xpath = new DOMXpath($this->dom);
        foreach ($xpath->query('/klarna/estore') as $estore) {
            $eid = $estore->getAttribute('id');

            foreach ($xpath->query('pclass', $estore) as $node) {
                $pclass = new KlarnaPClass();
                $pclass->setId(
                    $node->getAttribute('pid')
                );
                $pclass->setType(
                    $node->getAttribute('type')
                );
                $pclass->setEid($eid);
                $pclass->setDescription(
                    $xpath->query('description', $node)->item(0)->textContent
                );
                $pclass->setMonths(
                    $xpath->query('months', $node)->item(0)->textContent
                );
                $pclass->setStartFee(
                    $xpath->query('startfee', $node)->item(0)->textContent
                );
                $pclass->setInvoiceFee(
                    $xpath->query('invoicefee', $node)->item(0)->textContent
                );
                $pclass->setInterestRate(
                    $xpath->query('interestrate', $node)->item(0)->textContent
                );
                $pclass->setMinAmount(
                    $xpath->query('minamount', $node)->item(0)->textContent
                );
                $pclass->setCountry(
                    $xpath->query('country', $node)->item(0)->textContent
                );
                $pclass->setExpire(
                    $xpath->query('expire', $node)->item(0)->textContent
                );

                $this->addPClass($pclass);
            }
        }
    }
446349
public function fromXml(SimpleXMLElement $xmlElement)
    {
        $classname = $this->xmlElementToClassname($xmlElement);
        if (!is_null($classname)) {
            $return = new $classname();
            if ($return instanceof ArrayObject) {
                foreach ($xmlElement as $xmlChild) {
                    $return->append($this->fromXml($xmlChild));
                }
            } else {
                $objectData = array();
                foreach ($xmlElement as $xmlChild) {
                    $key = $this->xmlkeyToProperty($xmlChild->getName());
                    if (isset($objectData[$key])) {
                        if (!is_array($objectData[$key])) {
                            $objectData[$key] = array($objectData[$key]);
                        }
                        $objectData[$key][] = $this->fromXml($xmlChild);
                    } else {
                        $objectData[$key] = $this->fromXml($xmlChild);
                    }
                }
                $return->setData($objectData, false);
            }
        } else {
            $return = $this->castValue($xmlElement);
        }

        return $return;
    }
413767
public function loadAsXML()
    {
        $this->checkFileExists();
        $xml = new \DomDocument ();
        libxml_use_internal_errors(true);
        $result = $xml->load($this->absoluteFileName);
        if ($result) {
            return $xml;
        }
        $messageObject = ArrayUtil::getFromArray(libxml_get_errors(), 0);
        $libXMLMessage = ObjectUtil::getFromObject($messageObject, "message");
        $message = sprintf(self::EXCEPTION_INVALID_XML, $this->absoluteFileName, $libXMLMessage);
        $e = new \Exception(libxml_get_errors()[0]->message);
        libxml_clear_errors();
        throw $e;
    }
83476
final public function deserializeXml($xmlstr)
    {
        try {
            $element = new \SimpleXMLElement($xmlstr);
        } catch (\Exception $ex) {
            return false;
        }
        foreach ($element as $name => $value) {
            $this->$name = stripslashes(urldecode(htmlspecialchars_decode($value)));
        }

        return true;
    }
116644
private function loadFromExtensions(\DOMDocument $xml)
    {
        foreach ($xml->documentElement->childNodes as $node) {
            if (!$node instanceof \DOMElement || self::NS === $node->namespaceURI) {
                continue;
            }

            $values = static::convertDomElementToArray($node);
            if (!is_array($values)) {
                $values = array();
            }

            $this->container->loadFromExtension($node->namespaceURI, $values);
        }
    }
1152715
private static function array_to_xml($data = array(), &$xml_data) {
	foreach($data as $key => $value) {

	    if(is_array($value) or (is_object($value))) {
		if(!is_numeric($key)){
		    $subnode = $xml_data->addChild("$key");
		    self::array_to_xml($value, $subnode);
		}
		else{
		    $subnode = $xml_data->addChild("element");
		    self::array_to_xml($value, $subnode);
		}
	    }
	    else {
		if (is_bool($value)) {$value = $value ? "true" : "false";}
		$xml_data->addChild("$key","$value");
	    }
	}
    }
1263716
protected function parseElement(\XMLReader $xmlReader)
    {
        $elementName = $xmlReader->name;
        switch ($elementName) {
            case 'node':
                // update current node identifier
                $this->nodeIdentifierStack[] = $xmlReader->getAttribute('identifier');
                // update current path
                $nodeName = $xmlReader->getAttribute('nodeName');
                if ($nodeName !== '/' && $nodeName !== '') {
                    $this->nodeNameStack[] = Utility::renderValidNodeName($nodeName);
                }
                break;
            case 'variant':
                $path = $this->getCurrentPath();
                $parentPath = $this->getParentPath($path);

                $now = new Now();
                $currentNodeIdentifier = $this->nodeIdentifierStack[count($this->nodeIdentifierStack) - 1];
                $this->nodeDataStack[] = [
                    'Persistence_Object_Identifier' => Algorithms::generateUUID(),
                    'identifier' => $currentNodeIdentifier,
                    'nodeType' => $xmlReader->getAttribute('nodeType'),
                    'workspace' => $xmlReader->getAttribute('workspace'),
                    'sortingIndex' => $xmlReader->getAttribute('sortingIndex'),
                    'version' => $xmlReader->getAttribute('version'),
                    'removed' => (boolean)$xmlReader->getAttribute('removed'),
                    'hidden' => (boolean)$xmlReader->getAttribute('hidden'),
                    'hiddenInIndex' => (boolean)$xmlReader->getAttribute('hiddenInIndex'),
                    'path' => $path,
                    'pathHash' => md5($path),
                    'parentPath' => $parentPath,
                    'parentPathHash' => md5($parentPath),
                    'properties' => [],
                    'accessRoles' => [],
                    'creationDateTime' => $now,
                    'lastModificationDateTime' => $now,
                    'dimensionValues' => [] // is post-processed before save in END_ELEMENT-case
                ];
                break;
            case 'dimensions':
                $this->nodeDataStack[count($this->nodeDataStack) - 1]['dimensionValues'] = $this->parseDimensionsElement($xmlReader);
                break;
            case 'properties':
                $currentNodeIdentifier = $this->nodeDataStack[count($this->nodeDataStack) - 1]['identifier'];
                $this->nodeDataStack[count($this->nodeDataStack) - 1][$elementName] = $this->parsePropertiesElement($xmlReader, $currentNodeIdentifier);
                break;
            case 'accessRoles':
                $currentNodeIdentifier = $this->nodeDataStack[count($this->nodeDataStack) - 1]['identifier'];
                $this->nodeDataStack[count($this->nodeDataStack) - 1][$elementName] = $this->parseArrayElements($xmlReader, 'accessRoles', $currentNodeIdentifier);
                break;
            case 'hiddenBeforeDateTime':
            case 'hiddenAfterDateTime':
            case 'creationDateTime':
            case 'lastModificationDateTime':
            case 'lastPublicationDateTime':
                $stringValue = trim($xmlReader->readString());
                $dateValue = $this->propertyMapper->convert($stringValue, 'DateTime', $this->propertyMappingConfiguration);
                $this->nodeDataStack[count($this->nodeDataStack) - 1][$elementName] = $dateValue;
                break;
            default:
                throw new ImportException(sprintf('Unexpected element <%s> ', $elementName), 1423578065);
                break;
        }
    }
103880
protected function loadConfigurationFile(array $config, XmlFileLoader $loader)
    {
        foreach ($config as $filename) {
            if (file_exists($file = sprintf('%s/%s.xml', $this->getConfigurationDirectory(), $filename))) {
                $loader->load($file);
            }
        }
    }
698889
public function fromArray($arr)
    {
        $obj  = $this->getWorkerObject();
        foreach ($arr as $element) {
            $obj->clear();
            $obj->fromArray($element);
            $this->append($obj->toArray());
        }
    }
1285708
protected function xmlSerialize($data, $xml = null)
    {
        if ( !$xml instanceof SimpleXMLElement )
        {
            $xml = new SimpleXMLElement('<'. $this->requestName .' xmlns="'. $this->namespace .'" />');
        }

        foreach ($data as $key => $value)
        {
            if ( !isset($value) )
            {
                continue;
            }

            if ( is_array($value) )
            {
                $node = $xml->addChild($key);
                $this->xmlSerialize($value, $node);
            }
            else
            {
                $xml->addChild($key, $value);
            }
        }

        return $xml->asXML();
    }
1308927
protected function processLinkNode($xmlArray)
    {
        $link = [];
        $linkValue = $xmlArray[Resources::LINK];

        if (is_array($linkValue)) {
            /** @var SimpleXMLElement $linkValueInstance */
            foreach ($xmlArray[Resources::LINK] as $linkValueInstance) {
                $linkInstance = new AtomLink();
                $linkInstance->parseXml($linkValueInstance->asXML());
                $link[] = $linkInstance;
            }
        } else {
            $linkInstance = new AtomLink();
            $linkInstance->parseXml($linkValue->asXML());
            $link[] = $linkInstance;
        }

        return $link;
    }
1030442
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->ShipmentData->children() as $x){
            $a = array();

            if (isset($x->ShipmentId)){
                $a['ShipmentId'] = (string)$x->ShipmentId;
            }
            if (isset($x->ShipmentName)){
                $a['ShipmentName'] = (string)$x->ShipmentName;
            }

            //Address
            $a['ShipFromAddress']['Name'] = (string)$x->ShipFromAddress->Name;
            $a['ShipFromAddress']['AddressLine1'] = (string)$x->ShipFromAddress->AddressLine1;
            if (isset($x->ShipFromAddress->AddressLine2)){
                $a['ShipFromAddress']['AddressLine2'] = (string)$x->ShipFromAddress->AddressLine2;
            } else {
                $a['ShipFromAddress']['AddressLine2'] = null;
            }
            $a['ShipFromAddress']['City'] = (string)$x->ShipFromAddress->City;
            if (isset($x->ShipFromAddress->DistrictOrCounty)){
                $a['ShipFromAddress']['DistrictOrCounty'] = (string)$x->ShipFromAddress->DistrictOrCounty;
            } else {
                $a['ShipFromAddress']['DistrictOrCounty'] = null;
            }
            $a['ShipFromAddress']['StateOrProvinceCode'] = (string)$x->ShipFromAddress->StateOrProvinceCode;
            $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode;
            $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode;

            if (isset($x->DestinationFulfillmentCenterId)){
                $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId;
            }
            if (isset($x->LabelPrepType)){
                $a['LabelPrepType'] = (string)$x->LabelPrepType;
            }
            if (isset($x->ShipmentStatus)){
                $a['ShipmentStatus'] = (string)$x->ShipmentStatus;
            }

            $a['AreCasesRequired'] = (string)$x->AreCasesRequired;

            if (isset($x->ConfirmedNeedByDate)){
                $a['ConfirmedNeedByDate'] = (string)$x->ConfirmedNeedByDate;
            }
            
            $this->shipmentList[$this->index] = $a;
            $this->index++;
        }
    }