2011-10-29 64 views
38

我在CakePHP中輸出XML。但是,當我把我的XML爲驗證我得到這個錯誤:不允許處理指令匹配「[xX] [mM] [lL]」

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

我使用正確的XML佈局<?php echo $this->Xml->header(); ?>頂部則<?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> 

這有什麼不對嗎?

+9

你是否檢查XML是否在開始時沒有任何空格而生成? – elboletaire

回答

64

marmalad和El Boletaire Underave是正確的,你不能從一個空間開始,但這不是完整的故事。根據the XML spec,在XML prolog之前你根本就沒有任何東西。

由於您使用的是XML聲明,你必須用

<?xml version="1.0" ... 

在某些情況下,開始你的文件,像the byte order mark (BOM)非打印字符可以被佔用文件的前幾個字節帶來麻煩。

對於CakePHP更具體的問題,請檢查您的文件開頭或結尾沒有空白行/空白(即在?>之後或<?php之前)。

1

檢查您的XML文件,它可能以空格開始。如果你的XML文件以空格開頭,這種類型的異常將被拋出。

0

之前<?xml ?>標籤你不應該有任何空間。 這個標籤應該在第一行。 這對我有用