I need to mount a file in PHP
so I can download it in XML
:
The file I am mounting is divided below into "Fixed Title" and "Data that Bring Bank Information":
Fixed title
<ASCII-WIN>
<Version:5><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMYK:Process:0,0,0,1>>
<DefineParaStyle:tit=<Nextstyle:tit><cTypeface:Black><cSize:6.000000><pHyphenationLadderLimit:0><cLeading:7.000000><pHyphenationZone:34.000000><cFont:Arial><pMaxWordSpace:1.500000>
<pMinWordSpace:0.750000><pMaxLetterspace:0.250000><pMinLetterspace:-0.050000><pKeepFirstNLines:1><pKeepLastNLines:1><pRuleAboveColor:Black><pRuleAboveTint:100.000000><pRuleBelowColor:Black>
<pRuleBelowStroke:0.250000><pRuleBelowTint:70.000000>>
<DefineParaStyle:tex=<Nextstyle:tex><cTypeface:Regular><cSize:7.000000><pHyphenationLadderLimit:0><cLeading:7.500000><pHyphenationZone:34.000000><cFont:Times New Roman><pMaxWordSpace:1.500000>
<pMinWordSpace:0.750000><pMaxLetterspace:0.250000><pMinLetterspace:-0.050000><pKeepFirstNLines:1><pKeepLastNLines:1><pRuleAboveColor:Black><pRuleAboveTint:100.000000><pRuleBelowColor:Black>
<pRuleBelowStroke:0.250000><pRuleBelowTint:70.000000><pRuleBelowOn:1><pTextAlignment:JustifyLeft>>
Data that brings information from the bank
<ParaStyle:tit><cLanguage:Neutral>2 Casas - Gramados II
<cLanguage:><ParaStyle:tex>Sendo uma c/ 2 qts sal, coz, wc, gar outra c/ 2 côm grande c/ wc e coz. Troco p/ casa de - valor. Tel: 99636-2209 Salete (716) - R$190.000,00 - (Correio de Itapetininga)
<ParaStyle:tit><cLanguage:Neutral>2 Casas - Jd Itália
<cLanguage:><ParaStyle:tex>2 qts, sal, coz, quintal, gar, área de serviço + qt, coz, wc e área de serviço nos fundos. Tel: 99711-1096 (716) - R$350.000,00 - (Correio de Itapetininga)
<ParaStyle:tit><cLanguage:Neutral>2 Casas - Jd Santa Inês
<cLanguage:><ParaStyle:tex>Sendo uma em cima e outra em baixo. Tel: 99603-6098 (714) - R$120.000,00 - (Correio de Itapetininga)
What I have been able to do in PHP
:
<?php
/*
$link = mysqli_connect('mysql.sabapp.com.br', 'sabapp', 'sa134088');
*/
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "projeto_xml";
// Criar conexão
$conn = new mysqli($servername, $username, $password, $dbname);
// Conferir conexão
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "select id, titulo, texto, telefone, valor, empresa from site";
$result = $conn->query($sql);
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$cabecalho = "<ASCII-WIN>
<Version:5><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMYK:Process:0,0,0,1>>
<DefineParaStyle:tit=<Nextstyle:tit><cTypeface:Black><cSize:6.000000><pHyphenationLadderLimit:0><cLeading:7.000000><pHyphenationZone:34.000000><cFont:Arial><pMaxWordSpace:1.500000>
<pMinWordSpace:0.750000><pMaxLetterspace:0.250000><pMinLetterspace:-0.050000><pKeepFirstNLines:1><pKeepLastNLines:1><pRuleAboveColor:Black><pRuleAboveTint:100.000000><pRuleBelowColor:Black>
<pRuleBelowStroke:0.250000><pRuleBelowTint:70.000000>>
<DefineParaStyle:tex=<Nextstyle:tex><cTypeface:Regular><cSize:7.000000><pHyphenationLadderLimit:0><cLeading:7.500000><pHyphenationZone:34.000000><cFont:Times New Roman><pMaxWordSpace:1.500000>
<pMinWordSpace:0.750000><pMaxLetterspace:0.250000><pMinLetterspace:-0.050000><pKeepFirstNLines:1><pKeepLastNLines:1><pRuleAboveColor:Black><pRuleAboveTint:100.000000><pRuleBelowColor:Black>
<pRuleBelowStroke:0.250000><pRuleBelowTint:70.000000><pRuleBelowOn:1><pTextAlignment:JustifyLeft>>";
echo $cabecalho;
//Cabeçalho fixo
$site = $xml->createElement('Site');
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
//echo "ID: " . $row["id"]. " - Título: " . $row["titulo"]. " - Texto " . $row["texto"]. " - Telefone: " . $row["telefone"]. " - Valor: " . $row["valor"]. " - Empresa: " . $row["empresa"]. "<br>";
$item = $xml->createElement('Item');
$titulo = $xml->createElement('ParaStyle' , $row["titulo"]);
$texto = $xml->createElement('texto' , $row["texto"]);
$telefone = $xml->createElement('telefone', $row["telefone"]);
$valor = $xml->createElement('valor' , $row["valor"]);
$empresa = $xml->createElement('empresa' , $row["empresa"]);
$item->appendChild($titulo);
$item->appendChild($texto);
$item->appendChild($telefone);
$item->appendChild($valor);
$item->appendChild($empresa);
$site->appendChild($item);
}
}
else
{
echo "0 results";
}
$xml->appendChild($site);
header('content-type: text/xml');
print $xml->saveXML();
$conn->close();
?>
The result I got with this code printing in the browser is:
IfIgowiththeRightButtoninthebrowser->ViewPageSourceCodeIhavethefollowingcode:
1) I would like help to finalize, I am not able to put the Title part along with what is coming from the bank;
2) I am doing code with always children in XML
because I did not find anyone using without, I do not know how to do, I needed to use only sometimes with no bond with children.