PDA

View Full Version : generating an xml file via php


rlemon
10-13-2005, 02:49 PM
how would this be done?

change the header information of a php file to make it xml i'm assuming?

i've searched the forums and google quickly with no luck.
if anyone can point me in the direction of a good tutorial or guide on how to do this please let me know?

Can i place php code in an xml file?

xiaodao
10-13-2005, 04:35 PM
keen to know too, i also seeking such tutorials, i know there is something called xml_tree, but what is the best methods to generate xml files using php? if you know the answer, please also tell me, your help is greatly appreciated

gsnedders
10-13-2005, 04:53 PM
<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
?>

<gah>
<echo><?php echo $blah; ?></echo>
</gah>

You just looking for something like that?

rlemon
10-13-2005, 06:24 PM
I kept getting 'Header Already sent at....' when using that method.

i've now decided i will generate my own xml file:



$myFile = "./FileName.xml";
$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = '';
fwrite($fh, $stringData); // clear xml file

$stringData.= 'your XML'; // xml content

fwrite($fh, $stringData); // load new xml data
fclose($fh);

gsnedders
10-13-2005, 08:13 PM
I kept getting 'Header Already sent at....' when using that method.
Any whitespace before the header('')? Anything sent to the browser before the header('') will cause an error. The header('') must be first.

rlemon
10-13-2005, 08:30 PM
i had <? header('....'); ?> as line1;
i also tried:
<?
header(..);
?>

still got the error. i know what your saying about first line in the doc however it was still returning an error for me.

using the method i have used works perfect 100% of the time (so far)

Dave Smith-Haye
10-13-2005, 10:05 PM
Do yo uhave any HTML before the first php tag?

rlemon
10-13-2005, 11:38 PM
Do yo uhave any HTML before the first php tag?

no, as i said in the post it was line1.

it confused me why it was not working (because it should have been_), so i switched and generated the xml file if non existed, or re-wrote the existing file.