<?php
include_once("cidades.php");
//Chama objeto cidades passando parametro por UF
$cidades = new cidades();
$cidades->id_uf = $_POST["id_uf"];
$lst = $cidades->get_cidades();
//Verifica se o array tem resultados
if ($cidades->count > 0)
{
//Cria XML
$xml = new DOMDocument("1.0", "UTF-8");
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
//Insere n� principal
$root = $xml->createElement("cidades");
//Varre o array
foreach($lst as $city)
{
//Atribui vari�veis pra criar campos com o valor de cada registro
$id_uf = $xml->createElement("id_uf", $city->id_uf);
$id_cidade = $xml->createElement("id_cidade", $city->id_cidade);
$sigla = $xml->createElement("sigla", utf8_encode($city->sigla));
$nome = $xml->createElement("nome", utf8_encode($city->nome));
//Cria n� de registro
$cidade = $xml->createElement("cidade");
//Adiona campos com os valores
$cidade->appendChild($id_uf);
$cidade->appendChild($id_cidade);
$cidade->appendChild($sigla);
$cidade->appendChild($nome);
//Adiciona o registro ao n� prncipal
$root->appendChild($cidade);
}
//Fecha a TAG do n� principal
$xml->appendChild($root);
//Imprime o XML na tela
Header("Content-Type: text/xml");
echo $xml->saveXML();
}
?>