Last active
July 16, 2019 08:16
-
-
Save jagroop/9fd235bcefb45158850bb2c6d4282bf7 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
<?xml version="1.0" encoding="UTF-8"?> | |
<user_info> | |
<CANAL>10</CANAL> | |
<CLASE_DOC>ZPSE</CLASE_DOC> | |
<DEST_MCIA>0000000003</DEST_MCIA> | |
<ID_DEST_MCIA>BU</ID_DEST_MCIA> | |
<ID_RESP_PAGO>PY</ID_RESP_PAGO> | |
<ID_SOL>PE</ID_SOL> | |
<ORG_VTAS>VS01</ORG_VTAS> | |
<PEDIDO_ECOMMERCE>PEDIDO 1</PEDIDO_ECOMMERCE> | |
<RESP_PAGO>0000000003</RESP_PAGO> | |
<SECTOR>1</SECTOR> | |
<SOLICITANTE>0000000003</SOLICITANTE> | |
<FECHA>15.07.2019</FECHA> | |
<COMENTARIO>UN ALGO EN CABECERA</COMENTARIO> | |
<T_POSICIONES> | |
<item> | |
<MATERIAL>PRUEBAXX1</MATERIAL> | |
<CENTRO>Ifuel</CENTRO> | |
<CANTIDAD>2</CANTIDAD> | |
<UNIMED>PI</UNIMED> | |
<COMENTARIO>TESTIN API</COMENTARIO> | |
</item> | |
<item> | |
<MATERIAL>PRUEBAXX1</MATERIAL> | |
<CENTRO>Ifuel</CENTRO> | |
<CANTIDAD>2</CANTIDAD> | |
<UNIMED>PI</UNIMED> | |
<COMENTARIO>TESTIN API</COMENTARIO> | |
</item> | |
</T_POSICIONES> | |
</user_info> |
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 | |
header('Content-Type: application/xml'); | |
$users_array = array( | |
'CANAL' => 10, | |
'CLASE_DOC' => 'ZPSE', | |
'DEST_MCIA' => '0000000003', | |
'ID_DEST_MCIA' => 'BU', | |
'ID_RESP_PAGO' => 'PY', | |
'ID_SOL' => 'PE', | |
'ORG_VTAS' => 'VS01', | |
'PEDIDO_ECOMMERCE' => 'PEDIDO 1', | |
'RESP_PAGO' => '0000000003', | |
'SECTOR' => 1, | |
'SOLICITANTE' => '0000000003', | |
'FECHA' => '15.07.2019', | |
'COMENTARIO' => 'UN ALGO EN CABECERA', | |
'T_POSICIONES' => array( | |
'item' => array( | |
'MATERIAL' => 'PRUEBAXX1', | |
'CENTRO' => 'Ifuel', | |
'CANTIDAD' => '2', | |
'UNIMED' => 'PI', | |
'COMENTARIO' => 'TESTIN API', | |
), | |
array( | |
'MATERIAL' => 'PRUEBAXX1', | |
'CENTRO' => 'Ifuel', | |
'CANTIDAD' => '2', | |
'UNIMED' => 'PI', | |
'COMENTARIO' => 'TESTIN API', | |
), | |
), | |
); | |
function array_to_xml($array, &$xml_user_info) { | |
foreach ($array as $key => $value) { | |
if (is_array($value)) { | |
if (!is_numeric($key)) { | |
$subnode = $xml_user_info->addChild("$key"); | |
array_to_xml($value, $subnode); | |
} else { | |
// $subnode = $xml_user_info->addChild("item$key"); | |
$subnode = $xml_user_info->addChild("item"); | |
array_to_xml($value, $subnode); | |
} | |
} else { | |
$xml_user_info->addChild("$key", htmlspecialchars("$value")); | |
} | |
} | |
} | |
//creating object of SimpleXMLElement | |
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><user_info></user_info>"); | |
//function call to convert array to xml | |
array_to_xml($users_array, $xml_user_info); | |
//saving generated xml file | |
$xml_file = $xml_user_info->asXML(); | |
echo $xml_file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment