loadXML($xml); if ($returnAttribute == "") { //echo "XML".$xml."
"; return $this->getArray($dom); } else { $returnNodeList = $dom->getElementsByTagName($returnAttribute); $ret = []; foreach ($returnNodeList as $returnNode) { if ($returnNodeList->length == 1) { return $this->getArray($returnNode); } else { $ret[] = $this->getArray($returnNode); } } return $ret; } } public function getArray($node) { if (is_null($node) || !is_object($node)) { return $node; } $array = false; /* echo("!!!!!!!! NODE " . XML_TEXT_NODE . " :: name = " . $node->nodeName . " :: local = " . $node->localName . " :: childs ? " . $node->hasChildNodes() . " :: count = " . ($node->hasChildNodes() ? $node->childNodes->length : -1) . " :: type = " . $node->nodeType . " :: val = " . $node->nodeValue . "\n"); /* if ($node->hasAttributes()) { foreach ($node->attributes as $attr) { $array[$attr->nodeName] = $attr->nodeValue; } } */ if ($node->hasChildNodes()) { foreach ($node->childNodes as $childNode) { if ($childNode->nodeType != XML_TEXT_NODE) { if ($node->hasAttributes()) { foreach ($node->attributes as $attr) { if ($attr->localName == "nil") { return null; } } } if ($childNode->childNodes->length == 1) { $array[$childNode->localName] = $this->getArray($childNode); } else { $array[$childNode->localName][] = $this->getArray($childNode); } } else { return $childNode->nodeValue; //echo("!!!!!!!! TEXT " . $childNode->nodeValue . "\n"); //$array[$childNode->localName] } } } return $array; } public function getError() { return false; } public function fault() { return false; } }