protected function array2xmlImpl($array, $num_prefix = "num_", $depth = 0) { $depth++; // echo ( "[$depth]array2xmlImpl:" . print_r ( $array , true ) . "<br>"); // echo ( "[$depth]--array2xmlImpl: $num_prefix <br>"); $result = ""; if ($array instanceof myBaseObject) { /* * $obj = objectWrapperBase::toArrayImpl ( $array ); $result.= self::array2xmlImpl( $array, $num_prefix , $depth); */ $result = null; $fields = $array->getFieldNames(); foreach ($fields as $key) { if (empty($key)) { continue; } $val = $array->get($key); // TODO - think if want to compare to === null - // this will return 0 and empty strings (doesn't happen now) //if ( empty ( $val ) && ( $val !== 0 ) ) continue; if (!self::shouldDisplayValue($val)) { continue; } try { $key = self::tagNameFromField($key, $num_prefix); // fix key if needed $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">"; } catch (Exception $ex) { $result .= "<" . $key . ">ERROR</" . $key . ">"; } } } else { if ($array instanceof objectWrapperBase) { /* $obj = $array->toArray(); $result.= self::array2xmlImpl( $array, $num_prefix , $depth); */ $result = ""; $fields = $array->getFieldNames(); $i = 0; foreach ($fields as $key) { if (empty($key)) { continue; } $val = $array->get($key); if (!self::shouldDisplayValue($val)) { continue; } try { $key = self::tagNameFromField($key, $num_prefix); // fix key if needed $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">"; } catch (Exception $ex) { $result .= "<" . $key . ">ERROR</" . $key . ">"; } } } elseif (is_array($array)) { $result = ""; if (kArray::array_is_associative($array)) { foreach ($array as $key => $val) { try { $key = self::tagNameFromField($key, $num_prefix); // fix key if needed $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">"; } catch (Exception $ex) { $result .= "<" . $key . ">ERROR</" . $key . ">"; } } } else { $array_size = count($array); for ($i = 0; $i < $array_size; ++$i) { if (key_exists($i, $array)) { $val = $array[$i]; } else { } try { $key = self::tagNameFromField($i, $num_prefix); // fix key if needed $result .= "<" . $key . ">" . self::array2xmlImpl($val, $num_prefix, $depth) . "</" . $key . ">"; } catch (Exception $ex) { $result .= "<" . $key . ">ERROR</" . $key . ">"; } } } } elseif (is_object($array)) { return "ERROR fromating object of type [" . get_class($array) . "]"; //echo ( "[$depth]array2xmlImpl:is_object " . get_class ( $array ) . "<br>" ); } else { //cho ( "[$depth]array2xmlImpl: " . get_class ( $array ) . "<br>"); //return htmlentities ( $array ); if ($this->escape_text) { // TODO - decide whether to encode or cdata or nothing - according to the name of the field $escaped = kString::xmlEncode($array); return $escaped; /* if ( $escaped != $array ) { return "<![CDATA[$array]]>"; } */ } return $array; } } return $result; }