处理指令目标匹配“ ”是不允许的

我在CakePHP中输出XML。 但是当我将XML放入validation器时,出现此错误:

The processing instruction target matching "[xX][mM][lL]" is not allowed. 

我正在使用正确的XML布局<?php echo $this->Xml->header(); ?> <?php echo $this->Xml->header(); ?>在顶部然后<?php echo $content_for_layout; ?> <?php echo $content_for_layout; ?>

我的结果是:

 <?xml version="1.0" encoding="UTF-8" ?><response type='' outcome='true' message='Login successful!'> <user id='1234' total_number_of_completed_tasks='0' total_number_of_declined_tasks='0' total_number_of_passed_tasks='1' total_number_of_failed_tasks='1' reputation_points='99' deviant_points='0' /> <tasks> <accepted> <accepted_task id='4' type='Good' time_limit='500' details='Good accepted' /> <accepted_task id='5' type='OK' time_limit='660' details='Ok New task' /> <accepted_task id='9' type='Excellent' time_limit='2000' details='Great failed task' /> <accepted_task id='11' type='Your type' time_limit='222' details='Running and swimming all the way to Japan' /> <accepted_task id='7' type='Man' time_limit='744' details='My dirty task' /> </accepted> <pending> <pending_task id='8' type='Women' time_limit='5151' details='Women new task' sender_id='11111' sent_date='2031-01-01 00:00:00' sender_name='Jae Choi' /> </pending> <completed> </completed> <new> <new_task id='5' type='OK' time_limit='660' details='Ok New task' /> <new_task id='8' type='Women' time_limit='5151' details='Women new task' /> <new_task id='4' type='Good' time_limit='500' details='Good accepted' /> <new_task id='10' type='Hello' time_limit='122' details='What is this?' /> <new_task id='3' type='Best' time_limit='880' details='Stop doing work!' /> <new_task id='11' type='Your type' time_limit='222' details='Running and swimming all the way to Japan' /> <new_task id='6' type='Great' time_limit='553' details='Great accepted task' /> <new_task id='7' type='Man' time_limit='744' details='My dirty task' /> <new_task id='9' type='Excellent' time_limit='2000' details='Great failed task' /> </new> </tasks> </response> 

这有什么不对吗?

marmalad和El Boletaire Underave是正确的,你不能从一个空间开始,但这不是完整的故事。 根据XML规范 ,在XML prolog之前你什么也得不到。

由于您正在使用XML声明,因此您必须使用文件开始

 <?xml version="1.0" ... 

在某些情况下,像字节顺序标记(BOM)这样的非打印字符会占用文件的前几个字节,从而造成麻烦。

对于更特定于CakePHP的问题,请检查您的文件开头或结尾是否有空白行/空白(例如在?>或在<?php之前)。

正如El Boletaire Underave所说 ,检查XML是否在开始时没有任何空白的情况下生成。 这帮助我与我的XML。

检查您的XML文件,它可能以空格开始。 如果您的XML文件以空格开头,则会引发此types的exception。

之前<?xml ?>标签你不应该有任何空间。 这个标签应该在第一行。 这对我工作