开发者

CodeIgniter output XML in View

I tried to output XML in the view file. The view file is 开发者_开发知识库result_view.php and its first line is

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

But I get the error "Content is not allowed in prolog". So how to do this correctly? I use Eclipse + PDT.


One easy solution is to set php header in the view file and then echo the xml header.

Put this in the top of your view file:

<?php header ("Content-Type:text/xml"); ?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>';?>


This error seems to indicate that you have data before your <?xml ?> declaration. You might have a Byte Order Mark at the beginning of your file.

Try opening your file in an editor that will allow you to remove any BOM (such as Notepad++), or an editor with the capability to view files in hexadecimal format. There are also several tools you can use for removing BOMs. Google for more info, as the tool you use will vary depending on your situation and environment.


I don't know if this causes any problem, but I disabled PHP short open tag in .htaccess file, and <?xml worked. PHP no longer attempted to parse <? as php script.


<&#063;xml version="1.0" encoding="utf-8" standalone="yes"&#063;>

In html looks good, BUT then the receiver (application) must replace the and#063; to ?.


Codeigniter 4 update

    $this->response->setHeader('Content-Type', 'text/xml');


Why are you using php tags to echo out a simple string?

How about just putting this at the top of your view:

<?xml version="1.0" encoding="UTF-8"?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜