Skip to content

Commit 922ef7a

Browse files
committed
Added possibility to add attributes to XML elements
1 parent 8d7d175 commit 922ef7a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

application/libraries/Format.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,24 @@ public function to_xml($data = null, $structure = null, $basenode = 'xml')
127127
// replace anything not alpha numeric
128128
$key = preg_replace('/[^a-z_\-0-9]/i', '', $key);
129129

130+
if ($key === '_attributes' && (is_array($value) || is_object($value)))
131+
{
132+
$attributes = $value;
133+
if (is_object($attributes)) $attributes = get_object_vars($attributes);
134+
135+
foreach ($attributes as $attributeName => $attributeValue)
136+
{
137+
$structure->addAttribute($attributeName, $attributeValue);
138+
}
139+
}
130140
// if there is another array found recursively call this function
131-
if (is_array($value) || is_object($value))
141+
else if (is_array($value) || is_object($value))
132142
{
133143
$node = $structure->addChild($key);
134144

135145
// recursive call.
136146
$this->to_xml($value, $node, $key);
137147
}
138-
139148
else
140149
{
141150
// add single node.
@@ -267,4 +276,4 @@ private function _from_serialize($string)
267276

268277
}
269278

270-
/* End of file format.php */
279+
/* End of file format.php */

0 commit comments

Comments
 (0)