Blank line in XML document

Go To StackoverFlow.com

0

I'm developing a php web service which generates some plists so I can use them in my iPhone app. It's everything working perfectly, except for this blank line that appears in the end of the document and makes it unreadable by my app. What could it be? I'm sure all the tags are being properly opened and closed.

Thanks!

2012-04-04 00:35
by gabriel_vincent


1

After you generate your xml, you could add this one step...

$xml = trim( file_get_contents( YOUR_XML_FILE_PATH ) );
file_put_contents( YOUR_XML_FILE_PATH, $xml );

Hope it helps...

2012-04-05 07:12
by web-nomad
Thanks for the answaer! I had already solved my problem: I loaded the XML as a string and substringed it by one, removeing the last character. But your solution is even better - gabriel_vincent 2012-04-05 13:16


0

You might have a newline after a closing PHP tag in one of your files:

1. <?php
2. echo $xml;
3. ?>
4. 

For this reason, I find it preferable to not close the last ?> in the majority of my files. PHP will automatically close at the end of a file.

1. <?php
2. echo $xml;
3. 
2012-04-04 00:39
by kingcoyote
It didn't work... I actually don't print the XML in my page. I generate it, save in a folder in the server it and print only a path to a file in my server for the iPhone to use - gabriel_vincent 2012-04-04 00:44