Cakephp生成xml错误 - 空格 [英] Cakephp generating xml error - blank space

查看:192
本文介绍了Cakephp生成xml错误 - 空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的控制器代码:


$

b $ b

 配置:: write('debug',0); 
$ this-> layout = null;
header('Content-type:text / xml');
echo<?xml version = \1.0\?>;

View如下所示:

 < abc> 
something
< / abc>

输出可能如预期:

 <?xml version =1.0?>< abc> something< / abc> 

唯一的问题是在<?xml 给我一个错误:

  XML解析错误:XML或文本声明不在实体开始
行号1,列2:
<?xml version =1.0?>< abc>某事< / abc>
- ^



我知道这个问题在PHP中,当你有php-start和end标签它留下一个空间并创建问题,所以,我试图从视图中移动 echo<?xml ver ... 到控制器,以避免它

解决方案





由于php结束标签不是强制性的,因此在所有的结束标签中删除任何结束标签你的模型(如果有),你问的控制器,从app_controller.php和app_model.php和从你的视图助手...它应该在某个地方,但它是不容易找到



EDIT :事实上,它也可能是php begin标签之前的一个空格,查看这些文件,并检查begin标签是否位于文件



重新编辑:有些人已经为您自动创建了一些脚本,请查看:



http://ragrawal.wordpress.com/2007/11/07/script-for-removing-blank-spaces-before-and-after-php-tags/


I am trying to generate a dynamic xml document in CakePHP to output to the browser.

Here is my controller code:

Configure::write ('debug', 0);
$this->layout = null;
header('Content-type: text/xml');
echo "<?xml version=\"1.0\"?>";

View is something like this:

<abc>
     something
</abc>

The output is probably as expected:

<?xml version="1.0"?><abc>something</abc>

The only problem is that there is a space before <?xml giving me an error:

XML Parsing Error: XML or text declaration not at start of entity
Line Number 1, Column 2:
 <?xml version="1.0"?><abc> something </abc>
-^

I know this problem in PHP, when you have php-start and end tags it leaves a space and creates problems, so, I tried to move the line echo "<?xml ver... to controller from the view to avoid that but it didn't help.

Thanks in advance. -happyhardik

解决方案

Yes, the problem should be an space after the php end tag somewhere.

As the php end tag is not mandatory, remove any end tag in all your models (if there're any), the controller you're asking about, from app_controller.php and app_model.php and from your view helpers... It should be somewhere but it is not easy to find

EDIT: In fact it could be also an space before the php begin tag, look into those files and check that the begin tag is at the absolute beginning of the file

EDIT AGAIN: There are people that have created some scripts for doing that automatically for you, take a look to:

http://ragrawal.wordpress.com/2007/11/07/script-for-removing-blank-spaces-before-and-after-php-tags/

这篇关于Cakephp生成xml错误 - 空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆