Autor Zpráva
ludvalb
Profil
Ahoj,
mám problém, který se již několik dní snažím vyřešit a nevím stále co s tím.

Mám tento script:
<?php
$xml=simplexml_load_file("./XML_import_data/aukro.xml");

  foreach ($xml->transactions->transaction as $item){
      $OrderId = $item->OrderId;
      $CustomerLogin = $item->CustomerLogin;

      echo $OrderId." -".$CustomerLogin.".<BR>";
  } 
?>

a toto xml vygenerované z aukra:

<?xml version="1.0" encoding="UTF-8"?>
<transactions>
 <range>
  <from>06.03.2014</from>
  <to>13.03.2014</to>
  <sections>Archiv</sections>
 </range>
 <transaction>
  <parentId/>
  <Id>101245513215650399</Id>
  <Name>Prima</Name>
  <OrderId>4034546132458173961</OrderId>
  <CustomerLogin>8016</CustomerLogin>
  <CustomerEmail>xxx@seznam.cz</CustomerEmail>
  <CustomerName>liba</CustomerName>
  <CustomerPhone>777777777</CustomerPhone>
  <CustomerAddress>ulice 135</CustomerAddress>
  <CustomerZip>052 03</CustomerZip>
  <CustomerCity>obec</CustomerCity>
  <CustomerCountryCode>CZ</CustomerCountryCode>
  <CustomerCountryName>Česká republika</CustomerCountryName>
  <RecipientName>liba</RecipientName>
  <RecipientCompanyName/>
  <RecipientPhone>777777777</RecipientPhone>
  <RecipientAddress>ulice 135</RecipientAddress>
  <RecipientZip>052 03</RecipientZip>
  <RecipientCity>obec</RecipientCity>
  <RecipientCountryCode>CZ</RecipientCountryCode>
  <RecipientCountryName>Česká republika</RecipientCountryName>
  <InvoiceName/>
  <InvoiceCompanyName/>
  <InvoiceAddress/>
  <InvoiceZip/>
  <InvoiceCity/>
  <InvoiceCountryCode/>
  <InvoiceCountryName/>
  <VAT-ID/>
  <Total>19</Total>
  <Currency>CZK</Currency>
  <ExchangeRate>1</ExchangeRate>
  <SellDate>2014-03-06</SellDate>
  <DeliveryCost>12</DeliveryCost>
  <DeliveryType>Dobírka</DeliveryType>
  <PaymentType>Platba při převzetí</PaymentType>
    <subtransactions>
   <subtransaction>
    <transactionId>10190659</transactionId>
    <Id>10190657</Id>
    <Name>Prima</Name>
    <OrderId>4025998890</OrderId>
    <SellDate>2014-03-09</SellDate>
   </subtransaction>
   <subtransaction>
    <transactionId>10190659</transactionId>
    <Id>10190652</Id>
    <Name>Prima2</Name>
    <OrderId>4029004397</OrderId>
    <SellDate>2014-03-09</SellDate>
   </subtransaction>
   <subtransaction>
    <transactionId>10190659</transactionId>
    <Id>10190654</Id>
    <Name>Prima3</Name>
    <OrderId>4027266514</OrderId>
    <SellDate>2014-03-09</SellDate>
   </subtransaction>
   <subtransaction>
    <transactionId>10190659</transactionId>
    <Id>10190656</Id>
    <Name>Prima4</Name>
    <OrderId>4029938917</OrderId>
    <SellDate>2014-03-09</SellDate>
   </subtransaction>
  </subtransactions>
  <positions>
   <position>
    <transactionId>101245513215650399</transactionId>
    <Name/>
    <Quantity>1</Quantity>
    <Price>69</Price>
    <OfferName>Prima</OfferName>
    <Signature/>
   </position>
  </positions>
  <notes>
   <note>
    <transactionId>101245513215650399</transactionId>
    <Author/>
    <Date>06.03.2014 16:59:46</Date>
    <Note>děkuji za vyřizení</Note>
   </note>
  </notes>
 </transaction>
</transactions>

Script mi ale hlásí chybu Invalid argument supplied for foreach()

Pokud ale do xml souboru na druhý řádek vložím <rss version="2.0"> a na konec dokumentu </rss>, pak je vše ok. Nevíte čím by to mohlo být. Popř. pokud by jste měl někdo lepší nápad jak dostat z dokumentu XML veškerá data do MySQL databáze, rád se přiučím. Výsledkem celé akce by měl být obět xml dokument, který budu vkládat o účetního systému a pro dopravce.

Všem zúčastněným předem děkuji.
Chro
Profil
Kořenový tag se neuvádí, takže rovnou $xml->transaction ...
ludvalb
Profil
Super, díky moc. už je to ok.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0