XmlDomConstruct

EXTENDS THE DOMDOCUMENT TO IMPLEMENT PERSONAL (UTILITY) METHODS.

Defined (1)

The class is defined in the following location(s).

/InvoiceXpressRequest-PHP-API/lib/XmlDomConstruct.php  
  1. class XmlDomConstruct extends DOMDocument { 
  2.  
  3. /** 
  4. * CONSTRUCTS ELEMENTS AND TEXTS FROM AN ARRAY OR STRING. 
  5. * THE ARRAY CAN CONTAIN AN ELEMENT'S NAME IN THE INDEX PART 
  6. * AND AN ELEMENT'S TEXT IN THE VALUE PART. 
  7. * IT CAN ALSO CREATES AN XML WITH THE SAME ELEMENT TAGNAME ON THE SAME 
  8. * LEVEL. 
  9. * EX: 
  10. * <NODES> 
  11. * <NODE>TEXT</NODE> 
  12. * <NODE> 
  13. * <FIELD>HELLO</FIELD> 
  14. * <FIELD>WORLD</FIELD> 
  15. * </NODE> 
  16. * </NODES> 
  17. * ARRAY SHOULD THEN LOOK LIKE: 
  18. * ARRAY ( 
  19. * "NODES" => ARRAY ( 
  20. * "NODE" => ARRAY ( 
  21. * 0 => "TEXT" 
  22. * 1 => ARRAY ( 
  23. * "FIELD" => ARRAY ( 
  24. * 0 => "HELLO" 
  25. * 1 => "WORLD" 
  26. * ) 
  27. * ) 
  28. * ) 
  29. * ) 
  30. * ) 
  31. * @PARAM MIXED $MIXED AN ARRAY OR STRING. 
  32. * @PARAM DOMELEMENT[OPTIONAL] $DOMELEMENT THEN ELEMENT 
  33. * FROM WHERE THE ARRAY WILL BE CONSTRUCT TO. 
  34. */ 
  35. public function fromMixed($mixed, DOMElement $domElement = null) { 
  36.  
  37. $domElement = is_null($domElement) ? $this : $domElement; 
  38.  
  39. if (is_array($mixed)) { 
  40. foreach( $mixed as $index => $mixedElement ) { 
  41.  
  42. if ( is_int($index) ) { 
  43. if ( $index == 0 ) { 
  44. $node = $domElement; 
  45. } else { 
  46. $node = $this->createElement($domElement->tagName); 
  47. $domElement->parentNode->appendChild($node); 
  48.  
  49. else { 
  50. $node = $this->createElement($index); 
  51.  
  52. if ($index == "items") // hack needed for InvoiceXpress 
  53. $node->setAttribute( 'type', 'array' ); 
  54.  
  55. $domElement->appendChild($node); 
  56.  
  57. $this->fromMixed($mixedElement, $node); 
  58.  
  59. } else { 
  60. $domElement->appendChild($this->createTextNode($mixed)); 
  61.  
  62.