private function getDataFromXmlFile($sFilename) { //load XML from file if (!file_exists($sFilename)) { throw new AnwBadCallException("import file not found"); } $sFileContent = AnwUtils::file_get_contents($sFilename); $oRootNode = AnwUtils::loadXml($sFileContent); $aaData = array(); $aaData['PAGEGROUPS'] = array(); $aaData['TIME'] = $oRootNode->getAttribute("time"); $aaData['FROM'] = AnwXml::xmlFileAttributeDecode($oRootNode->getAttribute("from")); $aaData['VERSION_ID'] = $oRootNode->getAttribute("version_id"); $aaData['VERSION_NAME'] = AnwXml::xmlFileAttributeDecode($oRootNode->getAttribute("version_name")); $aoPageGroupsNodes = AnwXml::xmlGetChildsByTagName(self::XMLTAG_PAGEGROUP, $oRootNode); foreach ($aoPageGroupsNodes as $oPageGroupNode) { $aaDataGroup = array(); $aaDataGroup['CONTENTCLASS'] = AnwXml::xmlFileAttributeDecode($oPageGroupNode->getAttribute("contentclass")); $aaDataGroup['PAGES'] = array(); $aoTranslationsNodes = AnwXml::xmlGetChildsByTagName(self::XMLTAG_PAGE, $oPageGroupNode); foreach ($aoTranslationsNodes as $oPageNode) { $asDataPage = array(); $asDataPage['NAME'] = AnwXml::xmlFileAttributeDecode($oPageNode->getAttribute("name")); $asDataPage['LANG'] = AnwXml::xmlFileAttributeDecode($oPageNode->getAttribute("lang")); $asDataPage['TIME'] = (int) $oPageNode->getAttribute("time"); $asDataPage['CONTENT'] = AnwUtils::xmlDumpNodeChilds($oPageNode); $aaDataGroup['PAGES'][] = $asDataPage; } $aaData['PAGEGROUPS'][] = $aaDataGroup; } return $aaData; }
protected function loadContentFromXml($sXmlValue) { //print "<br/>".$this->getContentFieldsContainer()->getName()."::".htmlentities($sXmlValue)."<br/>"; $oNodeRoot = AnwUtils::loadXML('<doc>' . $sXmlValue . '</doc>'); $aoContentFields = $this->getContentFieldsContainer()->getContentFields(); foreach ($aoContentFields as $sFieldName => $oContentField) { //search <fieldname> tag in XML $aoFieldNameElements = AnwXml::xmlGetChildsByTagName($sFieldName, $oNodeRoot); //print "FIELDNAME:".$sFieldName."<br/>"; //print htmlentities(AnwUtils::xmlDumpNode($oNodeRoot)); //print_r($aoFieldNameElements); if (count($aoFieldNameElements) > 0) { $asValues = array(); //we shouldn't get more than one <fieldname> tag if (count($aoFieldNameElements) > 1) { throw new AnwUnexpectedException("Found more than 1 tag for " . $sFieldName); } $oFieldNameElement = array_pop($aoFieldNameElements); //print_r($oFieldNameElement); //print htmlentities(AnwUtils::xmlDumpNodeChilds($oFieldNameElement)); //loop for each <anwvalue> tag $aoValueElements = AnwXml::xmlGetChildsByTagName(self::XMLNODE_VALUE, $oFieldNameElement); foreach ($aoValueElements as $oValueElement) { $mFieldValue = AnwUtils::xmlDumpNodeChilds($oValueElement); //print "VALUE:".htmlentities($mFieldValue)."<br/>"; $asValues[] = $mFieldValue; } if ($oContentField instanceof AnwStructuredContentField_composed) { $this->aaoSubContents[$sFieldName] = array(); // recursive call for composed contentfield foreach ($asValues as $sSubContentValue) { //using $this insted of self:: for php inheritance pb $oSubContent = $this->rebuildContentFromXml($oContentField, $sSubContentValue); $this->aaoSubContents[$sFieldName][] = $oSubContent; } } else { // set atomic contentfield value $this->aasContentFieldsValues[$sFieldName] = $asValues; } } else { unset($this->aasContentFieldsValues[$sFieldName]); unset($this->aaoSubContents[$sFieldName]); } } $this->setXmlChanged(); }