protected function convertDom(\DOMNode $node)
{
$isArray = false;
$current = array();
$text = '';
if ($node instanceof \DOMElement) {
foreach ($node->attributes as $name => $attribute) {
$current["_{$name}"] = $attribute->value;
}
}
$parentTagName = $node instanceof \DOMElement ? $node->tagName : false;
foreach ($node->childNodes as $childNode) {
switch ($childNode->nodeType) {
case XML_ELEMENT_NODE:
$tagName = $childNode->tagName;
if (in_array($tagName, $this->fieldTypeHashElements)) {
$current[$tagName] = $this->parseFieldTypeHash($childNode);
} elseif (!isset($current[$tagName])) {
if (isset($this->forceList[$parentTagName]) && in_array($tagName, $this->forceList[$parentTagName], true)) {
$isArray = true;
$current[$tagName] = array($this->convertDom($childNode));
} else {
$current[$tagName] = $this->convertDom($childNode);
}
} elseif (!$isArray) {
$current[$tagName] = array($current[$tagName], $this->convertDom($childNode));
$isArray = true;
} else {
$current[$tagName][] = $this->convertDom($childNode);
}
break;
case XML_TEXT_NODE:
$text .= $childNode->wholeText;
break;
case XML_CDATA_SECTION_NODE:
$text .= $childNode->data;
break;
}
}
$text = trim($text);
if ($text !== '' && count($current)) {
$current['#text'] = $text;
} elseif ($text !== '') {
$current = $text;
} elseif (!count($current)) {
return null;
}
return $current;
}