Permalink
Browse files

Fixed missing attributes on repeating tags, closes #12.

  • Loading branch information...
1 parent f19a6e7 commit b9d238b5c20a72e6619b361bdf5a470907f00311 @jbroadway committed Dec 7, 2011
Showing with 18 additions and 2 deletions.
  1. +18 −2 ActiveResource.php
View
@@ -306,14 +306,30 @@ function _build_xml ($k, $v) {
}
if (is_array ($v)) {
foreach ($v as $key => $value) {
+ // handle attributes of repeating tags
+ if (is_numeric ($key) && is_array ($value)) {
+ foreach ($value as $sub_key => $sub_value) {
+ if (strpos ($sub_key, '@') === 0) {
+ $attrs .= ' ' . substr ($sub_key, 1) . '="' . $this->_xml_entities ($sub_value) . '"';
+ unset ($value[$sub_key]);
+ continue;
+ }
+ }
+ }
+
if (strpos ($key, '@') === 0) {
$attrs .= ' ' . substr ($key, 1) . '="' . $this->_xml_entities ($value) . '"';
continue;
}
$res .= $this->_build_xml ($key, $value);
$keys = array_keys ($v);
- if (is_numeric ($key) && $key != array_pop ($keys)) {
- $res .= '</' . $k . ">\n<" . $k . '>';
+ if (is_numeric ($key) && $key !== array_pop ($keys)) {
+ // reset attributes on repeating tags
+ if (is_array ($value)) {
+ $res = str_replace ('<' . $k . '{{attributes}}>', '<' . $k . $attrs . '>', $res);
+ $attrs = '';
+ }
+ $res .= '</' . $k . ">\n<" . $k . '{{attributes}}>';
}
}
} else {

0 comments on commit b9d238b

Please sign in to comment.