• User Attivo

    Generare file xml con php

    Ciao ragazzi, stò facendo un codice per generare un file xml in modo da interfacciarlo con un gestionale, il codice è questo solo che non funziona .(

    [PHP]
    <?php
    include("../../inc/config.php");
    $limite = "10";

    header("Content-type: text/xml; charset=utf-8");
    echo "<?xml version="1.0" encoding="UTF-8"?>";
    echo "<Company>";
    echo "<Name>Nome azienda</Name>";
    echo "<Address>Indirizzo azienda</Address>";
    echo "<Postcode>cap</Postcode>";
    echo " <City>citta</City>";
    echo "<Province>provincia</Province>";
    echo "<Country>Italia</Country>";
    echo "<FiscalCode>partita iva</FiscalCode>";
    echo "<VatCode>partita iva</VatCode>";
    echo "<Tel>tel</Tel>";
    echo "<Fax>fax</Fax>";
    echo "<Email>mail</Email>";
    echo "<HomePage>sito</HomePage>";
    echo "</Company>";
    echo " <Documents>";

    $query = @mysql_query("SELECT * FROM preventivi_clienti ORDER BY id DESC LIMIT 0," . $limite . "");
    while($result = @mysql_fetch_array($query))
    {
    $nome_db = $result['nome'];
    $nome_db = mb_convert_encoding(htmlspecialchars($nome_db , ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $cognome_db = $result['cognome'];
    $cognome_db= mb_convert_encoding(htmlspecialchars($cognome_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $indirizzo_db = $result['indirizzo'];
    $indirizzo_db = mb_convert_encoding(htmlspecialchars($indirizzo_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $cap_db = $result['cap'];
    $cap_db = mb_convert_encoding(htmlspecialchars($cap_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $citta_db = $result['citta'];
    $citta_db = mb_convert_encoding(htmlspecialchars($citta_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $stato_db = $result['stato'];
    $stato_db = mb_convert_encoding(htmlspecialchars($stato_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $telefono_db = $result['telefono'];
    $telefono_db = mb_convert_encoding(htmlspecialchars($telefono_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $email_db = $result['email'];
    $email_db = mb_convert_encoding(htmlspecialchars($email_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $data_db = $result['data'];
    $data_db = mb_convert_encoding(htmlspecialchars($data_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $note_db = $result['note'];
    $note_db = mb_convert_encoding(htmlspecialchars($note_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');
    ?>
    <Document>
    <DocumentType>C</DocumentType>
    <CustomerCode><?php echo $result[id]; ?></CustomerCode>
    <CustomerName><?php echo "$nome_db $cognome_db"; ?></CustomerName>
    <CustomerAddress><?php echo "$indirizzo_db"; ?></CustomerAddress>
    <CustomerPostcode><?php echo "$cap_db"; ?></CustomerPostcode>
    <CustomerCity><?php echo "$citta_db"; ?></CustomerCity>
    <CustomerProvince></CustomerProvince>
    <CustomerCountry><?php echo "$stato_db"; ?></CustomerCountry>
    <CustomerTel><?php echo "$telefono_db"; ?></CustomerTel>
    <CustomerEmail><?php echo "$email_db"; ?></CustomerEmail>
    <Date><?php echo "$data_db"; ?></Date>
    <Number></Number>
    <Total></Total>
    <PaymentName>Bonifico bancario</PaymentName>
    <PaymentBank>BANCA: UNICREDITBANCA AG. 884 GARIBALDI TRIESTE Codice IBAN: IT 83 Y 02008 02204 0000 15662502</PaymentBank>
    <CustomField1><?php echo "$note_db"; ?></CustomField1>
    <InternalComment>Nessun Acconto</InternalComment>
    <Row>
    <Code>0043</Code>
    <Description>Appendiabiti su ruote. In robusto metallo verniciato dotato di griglia portascarpe in filo metallico.</Description>
    <Qty>1</Qty>
    <Um>pz</Um>
    <Price>162</Price>
    <Discounts>5%</Discounts>
    <VatCode>20</VatCode>
    </Row>
    <Row>
    <Code>0039</Code>
    <Description>Cestini Gettacarta - Pareti in acciaio laminato nero o acciaio</Description>
    <Qty>3</Qty>
    <Um>pz</Um>
    <Price>16</Price>
    <Discounts>5%</Discounts>
    <VatCode>20</VatCode>
    </Row>

    </Document>
    

    <?
    }
    ?>

    </Documents>
    </EasyfattDocuments>

    [/PHP]

    Mi da questo errore

    This page contains the following errors:

    error on line 1 at column 405: Extra content at the end of the document
    Below is a rendering of the page up to the first error.

    Io in pratica dovrei generare un file xml con questa struttura solo nn capisco xke nn funziona 😞

    Ciau


  • User Attivo

    Nn ti puo' aiutare le libreria XMLWriter?


  • User Attivo

    developphp.com/tutorial_read.php?tid=72

    Nn rieesco a modificare il post precedente


  • Super User

    Come primo problema veco che manca il tag di apertura di </EasyfattDocuments>


  • User Attivo

    Adesso sn riuscito a generare il file

    [PHP]
    $query = mysql_query("
    SELECT *
    FROM preventivi_clienti
    INNER JOIN preventivi_prodotti
    ON preventivi_clienti.preventivi_clienti_ses = preventivi_prodotti.ses
    INNER JOIN shop_prodotti
    ON shop_prodotti.id = preventivi_prodotti.id_prodotto
    ");

    while($result = mysql_fetch_array($query))
    {
    $id_db = $result['preventivi_clienti_id'];
    $id_db= mb_convert_encoding(htmlspecialchars($id_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $nome_db = $result['preventivi_clienti_nome'];
    $nome_db = mb_convert_encoding(htmlspecialchars($nome_db , ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $cognome_db = $result['preventivi_clienti_cognome'];
    $cognome_db= mb_convert_encoding(htmlspecialchars($cognome_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $indirizzo_db = $result['preventivi_clienti_indirizzo'];
    $indirizzo_db = mb_convert_encoding(htmlspecialchars($indirizzo_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $cap_db = $result['preventivi_clienti_cap'];
    $cap_db = mb_convert_encoding(htmlspecialchars($cap_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $citta_db = $result['preventivi_clienti_citta'];
    $citta_db = mb_convert_encoding(htmlspecialchars($citta_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $stato_db = $result['preventivi_clienti_stato'];
    $stato_db = mb_convert_encoding(htmlspecialchars($stato_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $telefono_db = $result['preventivi_clienti_telefono'];
    $telefono_db = mb_convert_encoding(htmlspecialchars($telefono_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $email_db = $result['preventivi_clienti_email'];
    $email_db = mb_convert_encoding(htmlspecialchars($email_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $data_db = $result['preventivi_clienti_data'];
    $data_db = mb_convert_encoding(htmlspecialchars($data_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $note_db = $result['preventivi_clienti_note'];
    $note_db = mb_convert_encoding(htmlspecialchars($note_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $id_prodotto_db = $result['id_prodotto'];
    $id_prodotto_db = mb_convert_encoding(htmlspecialchars($id_prodotto_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $qnt_prod_db = $result['qnt'];
    $qnt_prod_db = mb_convert_encoding(htmlspecialchars($qnt_prod_db, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $nome_prodotto = $result['nome'];
    $nome_prodotto = mb_convert_encoding(htmlspecialchars($nome_prodotto, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $art_prodotto = $result['articolo'];
    $art_prodotto= mb_convert_encoding(htmlspecialchars($art_prodotto, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $unita_prodotto = $result['unita'];
    $unita_prodotto= mb_convert_encoding(htmlspecialchars($unita_prodotto, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    $prezzo_prodotto = $result['prezzo'];
    $prezzo_prodotto= mb_convert_encoding(htmlspecialchars($prezzo_prodotto, ENT_NOQUOTES, 'Windows-1252'), 'UTF-8', 'Windows-1252');

    echo "
    <Document>
    <DocumentType>C</DocumentType>
    <CustomerCode>$id_db</CustomerCode>
    <CustomerName>$nome_db $cognome_db</CustomerName>
    <CustomerAddress>$indirizzo_db</CustomerAddress>
    <CustomerPostcode>$cap_db</CustomerPostcode>
    <CustomerCity>$citta_db </CustomerCity>
    <CustomerProvince></CustomerProvince>
    <CustomerCountry>$stato_db </CustomerCountry>
    <CustomerVatCode></CustomerVatCode>
    <CustomerTel>$telefono_db</CustomerTel>
    <CustomerEmail>$email_db</CustomerEmail>
    <Date>$data_db</Date>
    <Number></Number>
    <Total></Total>
    <InternalComment>Nessun Acconto</InternalComment>
    <CustomField1>$note_db</CustomField1>
    <Row>
    <Code>$art_prodotto</Code>
    <Description>$nome_prodotto</Description>
    <Qty>$qnt_prod_db</Qty>
    <Um>pz</Um>
    <Price>$prezzo_prodotto</Price>
    <Discounts>5%</Discounts>
    <VatCode>20</VatCode>
    </Row>

    </Document>";
    

    }

    [/PHP]

    Il codice funziona, solo che non fà quello che voglio io, adesso vi spiego.

    Il codice mi da questo risultato

    cliente1
    prodotto1

    cliente1
    prodotto2

    cliente1
    prodotto3

    Io invece vorrei una cosa del genere

    cliente1
    prodotto1
    prodotto2
    prodotto3

    Il problema penso sia il while..

    Mi sapete dare un consiglio su come fare?

    Ciau