I'm dynamically creating an xml document in my php script with values from a
user form.
$xmlFile = "myxml.xml";
$fileHandle = fopen($xmlFile, 'wb') or die ('Could not open file!');
$xmlData = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
.
.
.
.
fclose($fileHandle);
all this works..a valid xml document is created just like i want
But my problem is reading it. I want to be able to insert a new element into the xml document
So this is what I do rite now:
readfile($fileName);
when i do this, it does not print the entire contents of the xml file.
It only prints the values of the elements. It skips the actual elemtns.
for example: if part of my xml is something like this
<student>
<name>John</name>
<address>123 street</address>
</student>
my code only prints
John 123 street
it skips the xml tags. I dont understand why. I've tried the other ways to read files too such as
fgets, fread, file() and it does the same. Only values of the elemtns are printed.
Someone please help me with this. Why aren't my xml tags getting printed.
Another thing i also tried was instead of making this an .xml file, i made it a simple .txt
and tried the same thing, but same result.
PLEASE help
problem with file(), fgets(), ..returning incomplete file
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Your script sounds like it is sending a content-type of for HTML, the default content-type for PHP to send.
Try calling header('Content-type: text/xml') before you output anything.
Try calling header('Content-type: text/xml') before you output anything.
still not working
when i tried header('Content-type: text/xml'); before i printed anything, i got the following warning:
Warning: Cannot modify header information - headers already sent by (output started at /www/cstv/html/admin/videoproject/test.php:10) in /www/cstv/html/admin/videoproject/test.php on line 274
but any how, the xml that i want to see did get printed in the page source. so the file is returning it..
but i want to be able to insert an element to the xml file, and then write it back using fwrite.
So what's the best way to do this?
Warning: Cannot modify header information - headers already sent by (output started at /www/cstv/html/admin/videoproject/test.php:10) in /www/cstv/html/admin/videoproject/test.php on line 274
but any how, the xml that i want to see did get printed in the page source. so the file is returning it..
but i want to be able to insert an element to the xml file, and then write it back using fwrite.
So what's the best way to do this?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Re: still not working
54 viewtopic.php?t=1157sachincrp wrote:Warning: Cannot modify header information - headers already sent by (output started at /www/cstv/html/admin/videoproject/test.php:10) in /www/cstv/html/admin/videoproject/test.php on line 274
Depending on your server's installed components, you could parse the XML inserting tags as needed, or use regex, or strpos()-substr_replace().. there are xml parsing tools on pear.php.net too: http://pear.php.net/search.php?q=xml&in=packagessachincrp wrote:but any how, the xml that i want to see did get printed in the page source. so the file is returning it..
but i want to be able to insert an element to the xml file, and then write it back using fwrite.
So what's the best way to do this?