Guest User

Untitled

a guest
Dec 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function xmlObjToArr($obj) {
  2. $namespace = $obj->getDocNamespaces(true);
  3. $namespace[NULL] = NULL;
  4.  
  5. $children = array();
  6. $attributes = array();
  7. $name = strtolower((string)$obj->getName());
  8.  
  9. $text = trim((string)$obj);
  10. if( strlen($text) <= 0 ) {
  11. $text = NULL;
  12. }
  13.  
  14. // get info for all namespaces
  15. if(is_object($obj)) {
  16. foreach( $namespace as $ns=>$nsUrl ) {
  17. // atributes
  18. $objAttributes = $obj->attributes($ns, true);
  19. foreach( $objAttributes as $attributeName => $attributeValue ) {
  20. $attribName = strtolower(trim((string)$attributeName));
  21. $attribVal = trim((string)$attributeValue);
  22. if (!empty($ns)) {
  23. $attribName = $ns . ':' . $attribName;
  24. }
  25. $attributes[$attribName] = $attribVal;
  26. }
  27.  
  28. // children
  29. $objChildren = $obj->children($ns, true);
  30. foreach( $objChildren as $childName=>$child ) {
  31. $childName = strtolower((string)$childName);
  32. if( !empty($ns) ) {
  33. $childName = $ns.':'.$childName;
  34. }
  35. $children[$childName][] = xmlObjToArr($child);
  36. }
  37. }
  38. }
  39.  
  40. return array(
  41. 'name'=>$name,
  42. 'text'=>$text,
  43. 'attributes'=>$attributes,
  44. 'children'=>$children
  45. );
  46. }
Add Comment
Please, Sign In to add comment