mardi 5 mai 2015

DomDocument XML output format

I got the following issue:

I'm creating an xml file with domdocument in php. The file looks very nice in a browser, but I wanna connect this xml file to an ERP.

I setup the following:

$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->save("file.xml");

And viewing the file.xml in total commander, with F4 (not F3) it clearly seems that this file is not same as my reference XML. No line breaks, instead of tabulators domdocument puts spaces into it. If I set preserveWhiteSpace to true, output is the same.

Is there any way to format is the same way as the reference, or my code is wrong, and I have to start the whole from the beginning?

Code that generates the rows in php:

$prodname = $dom->createElement("Termek_neve", $ordered_item->getname());
$Ordered_Items->appendChild($prodname);

$sku = $dom->createElement("Termekkod", $ordered_item->getSku());
$Ordered_Items->appendChild($sku);

$sku = $dom->createElement("Cikkszam", $ordered_item->getSku());
$Ordered_Items->appendChild($sku);

THIS IS THE REFERENCE XML, THAT OPENING WITH F4 IN Total Commander looks the same

<?xml version="1.0" encoding="iso-8859-2" ?>
<Header>
    <Megrendeles_adatai>
        <Rendeles_szama>MR4001</Rendeles_szama>
        <Datum>2014.01.03 13:15:49</Datum>
        <Fizetesi_mod>átutalás</Fizetesi_mod>
        <Szallitasi_mod>posta</Szallitasi_mod>
        <Megjegyzes_rendeleshez></Megjegyzes_rendeleshez>
        <Header_Vevo>
            <Vevo_neve>Minta Péter</Vevo_neve>
            <Vevo_irsz>1037</Vevo_irsz>
            <Vevo_varos>Budapest</Vevo_varos>
            <Vevo_cim>Duna u. 5.</Vevo_cim>
            <Szallitas_nev>Minta Péter</Szallitas_nev>
            <Szallitas_irsz>1037</Szallitas_irsz>
            <Szallitas_varos>Budapest</Szallitas_varos>
            <Szallitas_cim>Duna u. 5.</Szallitas_cim>
            <Telefon></Telefon>
            <Email>mintapeter@mintapeter.hu</Email>
            <Adoszam></Adoszam>
        </Header_Vevo>
        <Items>
            <Megrendelt_Tetelek>
                <Termek_neve>Férfi cipő</Termek_neve>
                <Termekkod>77866684</Termekkod>
                <Cikkszam></Cikkszam>
                <Mennyiseg>1</Mennyiseg>
                <Mee>pár</Mee>
                <Netto_egysegar>20000</Netto_egysegar>
                <AFA>27%</AFA>
                <Kedvezmeny_szazaleka>0</Kedvezmeny_szazaleka>
            </Megrendelt_Tetelek>
        </Items>
    </Megrendeles_adatai>
    <Megrendeles_adatai>
        <Rendeles_szama>MR4002</Rendeles_szama>
        <Datum>2014.01.04 12:05:49</Datum>
        <Fizetesi_mod>készpénz</Fizetesi_mod>
        <Szallitasi_mod>személyes átvétel</Szallitasi_mod>
        <Megjegyzes_rendeleshez></Megjegyzes_rendeleshez>
        <Header_Vevo>

And this is how the wrong outputted file looks like (yes, screenshot, 'cause if I ctrl CV it, looks great. But not working with my ERP)

enter image description here

Aucun commentaire:

Enregistrer un commentaire