Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Jak převést rozsáhlý *xml soubor do čitelnější formy?

Tak ono je to v tom Excelu rychlé i tak.
Teď zkouším převod xml do csv tímto skriptem, dělá to validní csv pomocí php funkce fputcsv a je to celkem rychlé (0.4 s OVM, 17 s FO, 21 s PO, 56 s PFO), ukládám nejdřív do paměti a pak naráz uložím do souboru.

<?php
//$t = "po";
//$t = "pfo";
//$t = "fo";
$t = "ovm";
$timer = -microtime(true);
$csv = fopen('php://memory', 'r+');
fputcsv($csv, array("id","type","subtype","firstName","lastName","tradeName","ico","city","district","street","cp","co","ce","zip","addressPoint","state","fullAddress","pdz","ovm","isMaster","idOVM"));
$xml = simplexml_load_file("datafile-seznam_ds_{$t}.xml");
foreach($xml as $box) {
	fputcsv($csv, array(
		$box->id,
		$box->type,
		$box->subtype,
		$box->name->person->firstName,
		$box->name->person->lastName,
		$box->name->tradeName,
		$box->ico,
		$box->address->city,
		$box->address->district,
		$box->address->street,
		$box->address->cp,
		$box->address->co,
		$box->address->ce,
		$box->address->zip,
		$box->address->addressPoint,
		$box->address->state,
		$box->address->fullAddress,
		$box->pdz,
		$box->ovm,
		$box->hierarchy->isMaster,
		$box->idOVM
	));
};
rewind($csv);
file_put_contents("datafile-seznam_ds_{$t}.csv", stream_get_contents($csv));
echo "Execution time: " . $timer + microtime(true) . " s";
?>

... a kdyby se někomu hodil převod z xml do sqlite pomocí php:
(na AMD 5600G: OVM 0.7 s, FO 26 s, PO 31 s, PFO 71 s)

<?php
$timer = -microtime(true);
//$t = "po";
//$t = "pfo";
//$t = "fo";
$t = "ovm";
$xml = simplexml_load_file("datafile-seznam_ds_{$t}.xml");
$pdo = new PDO('sqlite:ds.db', null, null, array(PDO::ATTR_PERSISTENT => true));
$pdo->beginTransaction();
foreach($xml as $box) {
	$dotaz = $pdo->prepare("INSERT into {$t} (id,type,subtype,firstName,lastName,tradeName,ico,city,district,street,cp,co,ce,zip,addressPoint,state,fullAddress,pdz,ovm,isMaster,idOVM) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
	$vysledek = $dotaz->execute(array(
		$box->id,
		$box->type,
		$box->subtype,
		$box->name->person->firstName,
		$box->name->person->lastName,
		$box->name->tradeName,
		$box->ico,
		$box->address->city,
		$box->address->district,
		$box->address->street,
		$box->address->cp,
		$box->address->co,
		$box->address->ce,
		$box->address->zip,
		$box->address->addressPoint,
		$box->address->state,
		$box->address->fullAddress,
		$box->pdz,
		$box->ovm,
		$box->hierarchy->isMaster,
		$box->idOVM
	));
};
$pdo->commit();
echo "Execution time: " . $timer + microtime(true) . " s";
?>

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny