Exemplo n.º 1
0
 function toXml()
 {
     if (true || $this->oCachedXml == null) {
         $oDoc = AnwUtils::newDomDocument();
         $oNodeRoot = $oDoc->createElement('doc');
         $oDoc->appendChild($oNodeRoot);
         //export fields
         $aoFields = $this->getContentFieldsContainer()->getContentFields();
         foreach ($aoFields as $sFieldName => $oContentField) {
             try {
                 $oNodeField = $oDoc->createElement($sFieldName);
                 if ($oContentField instanceof AnwStructuredContentField_atomic) {
                     $asFieldValues = $this->getContentFieldValues($sFieldName);
                     //export field values
                     //TODO : use getContentFieldValuesAsXml ?
                     foreach ($asFieldValues as $sFieldValue) {
                         $oValueNode = AnwXml::xmlCreateElementWithChilds($oNodeRoot->ownerDocument, self::XMLNODE_VALUE, $sFieldValue);
                         $oNodeField->appendChild($oValueNode);
                     }
                 } else {
                     //composed field
                     //$aoSubContents = $this->getSubContents($sFieldName, $bWithDefaultValues, $bWithMissingValues);
                     $aoSubContents = $this->getSubContents($sFieldName);
                     foreach ($aoSubContents as $oSubContent) {
                         $sSubContentValue = $oSubContent->toXmlString();
                         $oValueNode = AnwXml::xmlCreateElementWithChilds($oNodeRoot->ownerDocument, self::XMLNODE_VALUE, $sSubContentValue);
                         $oNodeField->appendChild($oValueNode);
                         //$oSubXmlNew = $oDoc->importNode($oSubXml->documentElement, true);
                     }
                     //print htmlentities(AnwUtils::xmlDumpNode($oNodeField));
                 }
                 $oNodeRoot->appendChild($oNodeField);
             } catch (AnwContentFieldValueNotFoundException $e) {
                 //we skip this node as it has no value and we requested $bThrowExceptionWhenMissing
             }
         }
         $this->oCachedXml = $oDoc;
     }
     return clone $this->oCachedXml;
 }