I am trying to write an API to write data to my POS system from magento. My POS supplier gives me a code on which I need to write the data in XML 1.0 format. I wrote the data using SimpleXML form, as I need to do some loops to get all the data I need.
The problem is that the API is not reading the data I wrote correctly. I've already tried to use DOM to reformat the code without success. How can I edit this SimpleXML so the data I post is as it was XML 1.0.
Apparently what causing the problem is the rawurlencode function that can't read SimpleXML, but my API only understands this way...
I am new to PHP and XML, so any suggestions are welcome. Thanks in advance.
$xml = '<?xml version="1.0" encoding="UTF-8"?><pedido></pedido>';
$xmlpost = new SimpleXMLElement($xml);
$pedidob = $xmlpost->addChild('pedido');
$clienteb = $pedidob->addChild('cliente');
$clientebno = $clienteb->addChild('nome',$nome);
$clientebcp = $clienteb->addChild('cpf_cnpj',$cpf);
$clienteben = $clienteb->addChild('endereco',$rua);
$clientebnu = $clienteb->addChild('numero',$numero);
$clientebco = $clienteb->addChild('complemento',$complemento);
$clientebba = $clienteb->addChild('bairro',$bairro);
$clientebce = $clienteb->addChild('cep',$cep);
$clientebci = $clienteb->addChild('cidade',$cidade);
$clientebuf = $clienteb->addChild('uf',$estado);
$clientebfo = $clienteb->addChild('fone',$telefone);
$clientebce = $clienteb->addChild('celular',$celular);
$clientebem = $clienteb->addChild('email',$email);
$itensb = $pedidob->addChild('itens');
for ($k = 0; $k < $arrayl; $k++) {
$itemb = $itensb->addChild('item');
$codigob = $itemb->addChild('codigo', $infopp[$k][0]);
$descricaob = $itemb->addChild('descricao', $infopp[$k][1]);
$qtdeb = $itemb->addChild('qtde', $infopp[$k][2]);
$vlrunitb = $itemb->addChild('vlr_unit', $infopp[$k][3]);
}
$parcelasb= $pedidob->addChild('parcelas');
$parcelab = $parcelasb->addChild('parcela');
$vlrb = $parcelab->addChild('vlr',$Subtotal);
$freteb = $pedidob->addChild('vlr_frete',$Shipping);
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = true;
$dom->formatOutput = true;
$dom->loadXML($xmlpost->asXML());
echo $dom->saveXML();
$posts = array (
"apikey" => "*******",
"xml" => rawurlencode($xmlpost)
);
</div>