Last active
August 29, 2015 13:56
-
-
Save drupalista-br/9230016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Structered array for convertion into XML. | |
| $data_array = array( | |
| array( | |
| '#xml_tag' => 'a', | |
| '#xml_value' => '', | |
| '#tag_attributes' => array( | |
| array( | |
| 'name' => 'a_attr_name', | |
| 'value' => 'a_attr_value', | |
| ), | |
| ), | |
| '#subnode' => array( | |
| array( | |
| '#xml_tag' => 'aa', | |
| '#xml_value' => 'aa_value', | |
| '#tag_attributes' => array( | |
| array( | |
| 'name' => 'aa_attr_name', | |
| 'value' => 'aa_attr_value', | |
| ), | |
| ), | |
| '#subnode' => FALSE, | |
| ), | |
| ), | |
| ), | |
| array( | |
| '#xml_tag' => 'b', | |
| '#xml_value' => 'b_value', | |
| '#tag_attributes' => FALSE, | |
| '#subnode' => FALSE, | |
| ), | |
| array( | |
| '#xml_tag' => 'c', | |
| '#xml_value' => 'c_value', | |
| '#tag_attributes' => array( | |
| array( | |
| 'name' => 'c_attr_name', | |
| 'value' => 'c_attr_value', | |
| ), | |
| array( | |
| 'name' => 'c_attr_name_1', | |
| 'value' => 'c_attr_value_1', | |
| ), | |
| ), | |
| '#subnode' => array( | |
| array( | |
| '#xml_tag' => 'ca', | |
| '#xml_value' => 'ca_value', | |
| '#tag_attributes' => FALSE, | |
| '#subnode' => array( | |
| array( | |
| '#xml_tag' => 'caa', | |
| '#xml_value' => 'caa_value', | |
| '#tag_attributes' => array( | |
| array( | |
| 'name' => 'caa_attr_name', | |
| 'value' => 'caa_attr_value', | |
| ), | |
| ), | |
| '#subnode' => FALSE, | |
| ), | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| // creating object of SimpleXMLElement | |
| $xml_object = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><nfeProc versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe"></nfeProc>'); | |
| // function call to convert array to xml | |
| // See https://gist.github.com/drupalista-br/9230202 | |
| array_to_xml($data_array, $xml_object); | |
| // saving generated xml file | |
| $xml_object->asXML('/tmp/test.xml'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment