public static function load(&$form, $xmlString) { //first load the xml String try { $formXml = new SimpleXMLElement($xmlString); } catch (Exception $e) { return Logg('Failure', '', "BAD XML format."); } return SimpleXml::load($form, $formXml); }
/** * Parses one table entry and returns the table name. * * @param \SimpleXml $result The original XML body loaded in XML. * * @return string */ private function _parseOneTable($result) { $query = ".//{$this->_dataServicesMetadataPrefix}:properties/"; $query .= "{$this->_dataServicesPrefix}:TableName"; $tableName = $result->xpath($query); $table = (string) $tableName[0]; return $table; }
/** * Takes an array and converts it to an xml child element of the given * child node. * * @param array $params * @param SimpleXml $child */ public function formatRequestXml($params, $child) { foreach ($params as $key => $value) { if (is_array($value)) { switch ($key) { case 'attributes': foreach ($value as $l => $b) { if (is_bool($b)) { $b = $b === true ? 'TRUE' : 'FALSE'; } $child->addAttribute($l, $b); } break; default: $childNode = $child->addChild($key); self::formatRequestXml($value, $childNode); } } elseif (!is_numeric($key)) { $child->addChild($key, $value); } else { $child[0] = $value; } } }
/** * Return the full inner content of an xml element. * * @todo Fully manage cdata * * @see OaiPmhStaticRepository_Harvest_Document::_innerXML() * * @param SimpleXml $xml * @return string */ protected function _innerXML($xml) { $output = $xml->asXml(); $pos = strpos($output, '>') + 1; $len = strrpos($output, '<') - $pos; $output = trim(substr($output, $pos, $len)); // Only main CDATA is managed, not inside content: if this is an xml or // html, it will be managed automatically by the display; if this is a // text, the cdata is a text too. $simpleXml = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); // Non XML data. if (empty($simpleXml)) { // Check if this is a CDATA. if ($this->_isCdata($output)) { $output = substr($output, 9, strlen($output) - 12); } elseif (json_decode($output) !== null) { $output = html_entity_decode($output, ENT_NOQUOTES); } else { $output = html_entity_decode($output); } } // Else this is an xml value, so no change because it's xml escaped. return trim($output); }