Skip to content

Commit

Permalink
Fixed missing attributes on repeating tags, closes #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbroadway committed Dec 7, 2011
1 parent f19a6e7 commit b9d238b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ActiveResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b9d238b

Please sign in to comment.