XML to CSV, only getting one line?

RISK47-FOR-LIFE

New Member
I'm having trouble with this XML to CSV Script.. when I remove the headers everything echos but with them I only get the last line of the CSV file. I turned off \[code\]E_NOTICE\[/code\] warnings as not all of the \[code\]delivery-requests\[/code\] have \[code\]customer-ref1\[/code\] and I'm not sure how to test for this \[code\]isset()\[/code\] doesn't seem to work. I suspect that it may be part of the issue.. anyways, here's the code:\[code\]<?phperror_reporting(E_ALL ^ E_NOTICE);if (isset($_FILES) && isset($_POST['submit'])) { $page = file_get_contents($_FILES['import']['tmp_name']); $doc = new DOMDocument(); $doc->loadXML($page); $delivery_requests = $doc->getElementsByTagName("delivery-request"); $count=0; foreach ($delivery_requests as $delivery_request) { $count++; $product_id = $delivery_request->getElementsByTagName("product-id")->item(0)->nodeValue; $weight = $delivery_request->getElementsByTagName("weight")->item(0)->nodeValue; $customer_ref1 = $delivery_request->getElementsByTagName("customer-ref1")->item(0)->nodeValue; $pre_tax_amount = $delivery_request->getElementsByTagName("pre-tax-amount")->item(0)->nodeValue; $item_id = $delivery_request->getElementsByTagName("pre-tax-amount")->item(0)->nodeValue; $mailing_date = $delivery_request->getElementsByTagName("mailing-date")->item(0)->nodeValue; ob_clean(); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=export.csv"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); echo $product_id . "," . $weight . "," . $customer_ref1 . "," . $pre_tax_amount . "," . $item_id . "," . $mailing_date . "\n"; } exit;} else { ?> <h2>Import XML<h2> <form action="import.php" method="post" enctype="multipart/form-data"> <input type="file" name="import"> <input type="submit" name="submit" value="http://stackoverflow.com/questions/3848370/Import"> <input type="button" value="http://stackoverflow.com/questions/3848370/Cancel" onclick="window.location='import.php'"> </form><?php}?>\[/code\]As always--Thanks!
 
Back
Top