http://forum.php.pl/index.php?showtopic=78...rt=#entry401680
W powyższym wątku brakuje rozwiązania problemu. Działam na plikach małych i mega dużych. Obecnie testuję na małych. Doradzono mi XMLreader do pracy z dużymi ale już widzę problem z pomijaniem węzłów i atrybutów bądź ich dublowaniem.
Dam przykład mojego działania:
kawałek xml-a
Kod
<trip date="2009-03-15" period="4" catalog="Z01" template="" id="15146">
<hotel code="SHANDRANJP" destCode="ITA"/>
</trip>
<hotel code="SHANDRANJP" destCode="ITA"/>
</trip>
Kod
$xml = new XMLReader();
$xml->open($plik);
while ($xml->read()) {
$date = $xml->getAttribute('date');
$period = $xml->getAttribute('period');
$catalog = $xml->getAttribute('catalog');
$template = $xml->getAttribute('template');
$id_ = $xml->getAttribute('id');
$hotel_code = $xml->getAttribute('country');
$hotel_descode = $xml->getAttribute('destCode');
}
$xml->open($plik);
while ($xml->read()) {
$date = $xml->getAttribute('date');
$period = $xml->getAttribute('period');
$catalog = $xml->getAttribute('catalog');
$template = $xml->getAttribute('template');
$id_ = $xml->getAttribute('id');
$hotel_code = $xml->getAttribute('country');
$hotel_descode = $xml->getAttribute('destCode');
}
Dodam że całość chcę wrzucić w bazę a żeby nie było pustych informacji zrobiłem coś na zasadzie
if(isset($date)) {
dalsze polecenie
}
W pliku mamy trip i hotel, co prawda atrybuty się nie dublują nazwami ale czy napewno odczytuje się je jednakową formułą? Są one w innych znacznikach. Wcześniej korzystałem z SimpleXML - b. proste w obsłudze, jednak nie ma bata przerobić nim kilkuset megowe pliki a mam nawet 1gb...
$id_ = $xml->getAttribute('id');
$hotel_code = $xml->getAttribute('country');