function NodeExportXmlDecoder::build in Node export 7.3
Same name and namespace in other branches
- 6.3 modules/node_export_xml/node_export_xml.module \NodeExportXmlDecoder::build()
1 call to NodeExportXmlDecoder::build()
- NodeExportXmlDecoder::decode in formats/
xml.inc
File
- formats/
xml.inc, line 153 - The Node export XML format handler.
Class
- NodeExportXmlDecoder
- Class for parsing Node export XML.
Code
function build($stack) {
$result = array();
if (count($stack['children']) > 0) {
$keycount = array();
foreach ($stack['children'] as $child) {
$keycount[] = $child['name'];
}
if (count(array_unique($keycount)) != count($keycount)) {
// Enumerated array.
$children = array();
foreach ($stack['children'] as $child) {
$children[] = $this
->build($child);
}
}
else {
// Associative array.
$children = array();
foreach ($stack['children'] as $child) {
if (!empty($stack['attributes']['_NUMERIC_KEYS'])) {
$child['name'] = intval(substr($child['name'], 1));
}
$children[$child['name']] = $this
->build($child);
}
}
$result = array_merge($result, $children);
}
if (count($result) == 0) {
// An atomic value.
$return = trim($stack['data']);
if (isset($stack['attributes']['TYPE'])) {
if ($stack['attributes']['TYPE'] == 'boolean') {
return trim($stack['data']) == 'TRUE' ? TRUE : FALSE;
}
elseif ($stack['attributes']['TYPE'] == 'NULL') {
return NULL;
}
}
elseif (!empty($stack['attributes']['_NUMERIC_KEYS'])) {
return array();
}
return htmlspecialchars_decode(trim($stack['data']));
}
else {
// An array or object.
if (isset($stack['attributes']['CLASS'])) {
$object = new $stack['attributes']['CLASS']();
foreach ($result as $k => $v) {
$object->{$k} = $v;
}
$result = $object;
}
return $result;
}
}