WCB_XML_Document

The WooCommerce Billogram Integration WCB XML Document class.

Defined (1)

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

/class-billogram2-xml.php  
  1. class WCB_XML_Document { 
  2.  
  3. /** @public String XML */ 
  4. var $xml; 
  5.  
  6. /** @public String version */ 
  7. var $ver; 
  8.  
  9. /** @public String Charset */ 
  10. var $charset; 
  11.  
  12. /** @public String Charset */ 
  13. var $exceptions; 
  14.  
  15. /** @public String Charset */ 
  16. var $countries; 
  17.  
  18. /** 
  19. */ 
  20. function __construct() { 
  21. $this->ver = '1.0'; 
  22. $this->charset = 'UTF-8'; 
  23. $this->exceptions = array( 
  24. 'Address1',  
  25. 'Address2',  
  26. 'DeliveryAddress1',  
  27. 'DeliveryAddress2',  
  28. 'Phone1',  
  29. 'Phone2',  
  30. ); 
  31.  
  32. $this->countries = array( 
  33. 'SE' => 'Sverige' 
  34. ); 
  35.  
  36. /** 
  37. * generates XML Document 
  38. * @access public 
  39. * @param $root 
  40. * @param array $data 
  41. * @internal param mixed $arr 
  42. * @return String 
  43. */ 
  44. function generate($root, $data=array()) { 
  45. $this->xml = new XmlWriter(); 
  46. $this->xml->openMemory(); 
  47. $this->xml->startDocument($this->ver, $this->charset); 
  48. $this->xml->startElement($root); 
  49. $this->write($this->xml, $data); 
  50. $this->xml->endElement(); 
  51. $this->xml->endDocument(); 
  52. $xml = $this->xml->outputMemory(true); 
  53. $this->xml->flush(); 
  54. return $xml; 
  55.  
  56. /** 
  57. * writes Element 
  58. * @access public 
  59. * @param mixed $xml , mixed $data 
  60. * @param $data 
  61. * @return void 
  62. */ 
  63. private function write(XMLWriter $xml, $data) { 
  64. foreach($data as $key => $value) { 
  65. if (!in_array($key, $this->exceptions)) { 
  66. $key = preg_replace("/[^A-Za-z?!]/", '', $key); 
  67. if(is_array($value)) { 
  68.  
  69. $xml->startElement($key); 
  70. $this->write($xml, $value); 
  71. $xml->endElement(); 
  72. continue; 
  73. else{ 
  74. if(isset($value)) { 
  75. $xml->writeElement($key, $value); 
  76.