久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CakePHP Xml 實(shí)用程序庫觸發(fā) DOMDocument 警告

CakePHP Xml utility library triggers DOMDocument warning(CakePHP Xml 實(shí)用程序庫觸發(fā) DOMDocument 警告)
本文介紹了CakePHP Xml 實(shí)用程序庫觸發(fā) DOMDocument 警告的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在使用 CakePHP 的 Xml 在視圖中生成 XML核心庫:

I'm generating XML in a view with CakePHP's Xml core library:

$xml = Xml::build($data, array('return' => 'domdocument'));
echo $xml->saveXML();

View 是由控制器提供的數(shù)組:

View is fed from the controller with an array:

$this->set(
    array(
        'data' => array(
            'root' => array(
                array(
                    '@id' => 'A & B: OK',
                    'name' => 'C & D: OK',
                    'sub1' => array(
                        '@id' => 'E & F: OK',
                        'name' => 'G & H: OK',
                        'sub2' => array(
                            array(
                                '@id' => 'I & J: OK',
                                'name' => 'K & L: OK',
                                'sub3' => array(
                                    '@id' => 'M & N: OK',
                                    'name' => 'O & P: OK',
                                    'sub4' => array(
                                        '@id' => 'Q & R: OK',
                                        '@'   => 'S & T: ERROR',
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
    )
);

無論出于何種原因,CakePHP 都會(huì)發(fā)出這樣的內(nèi)部調(diào)用:

For whatever the reason, CakePHP is issuing an internal call like this:

$dom = new DOMDocument;
$key = 'sub4';
$childValue = 'S & T: ERROR';
$dom->createElement($key, $childValue);

... 觸發(fā) PHP 警告:

... which triggers a PHP warning:

Warning (2): DOMDocument::createElement(): unterminated entity reference               T [CORECakeUtilityXml.php, line 292

... 因?yàn)?已記錄),DOMDocument::createElement 不轉(zhuǎn)義值.但是,正如測試用例所示,它只在某些節(jié)點(diǎn)上執(zhí)行此操作.

... because (as documented), DOMDocument::createElement does not escape values. However, it only does it in certain nodes, as the test case illustrates.

是我做錯(cuò)了什么還是我在 CakePHP 中遇到了一個(gè)錯(cuò)誤?

Am I doing something wrong or I just hit a bug in CakePHP?

推薦答案

問題似乎出在具有屬性和值的節(jié)點(diǎn)中,因此需要使用 @ 語法:

The problem seems to be in nodes that have both attributes and values thus need to use the @ syntax:

'@id' => 'A & B: OK',  // <-- Handled as plain text
'name' => 'C & D: OK', // <-- Handled as plain text
'@' => 'S & T: ERROR', // <-- Handled as raw XML

我寫了一個(gè)小輔助函數(shù):

I've written a little helper function:

protected function escapeXmlValue($value){
    return is_null($value) ? null : htmlspecialchars($value, ENT_XML1, 'UTF-8');
}

...并在我創(chuàng)建數(shù)組時(shí)手動(dòng)調(diào)用它:

... and take care of calling it manually when I create the array:

'@id' => 'A & B: OK',
'name' => 'C & D: OK',
'@' => $this->escapeXmlValue('S & T: NOW WORKS FINE'),

很難說它是錯(cuò)誤還是功能,因?yàn)?文檔 沒有提到它.

It's hard to say if it's bug or feature since the documentation doesn't mention it.

這篇關(guān)于CakePHP Xml 實(shí)用程序庫觸發(fā) DOMDocument 警告的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 成人av一区二区在线观看 | 亚洲天堂中文字幕 | 亚洲精品久久久久久久久久久久久 | 视频一区二区在线观看 | 久久精品小视频 | 国产一级免费在线观看 | 欧美精品一区二区三区在线播放 | 国产91九色 | 亚洲免费在线 | 性欧美精品一区二区三区在线播放 | 久久777| www久久国产 | 91麻豆精品国产91久久久久久久久 | 中文字幕视频在线看5 | 天天色天天色 | 国产高清在线精品一区二区三区 | 精品国产第一区二区三区 | 午夜www| 天天操,夜夜爽 | 欧美11一13sex性hd | 一级黄色播放 | 亚洲午夜av久久乱码 | 韩国电影久久 | 日本精品一区二区三区视频 | 日韩欧美亚洲 | 成人精品一区二区三区 | 青青久在线视频 | 精品影院 | 久久亚洲国产精品 | 亚洲免费久久久 | 中文字幕第一页在线 | 国产高潮av | 精品国产欧美一区二区三区成人 | 视频在线亚洲 | 色综合区 | 亚洲精品久久久久久久久久久久久 | 一区二区三区在线免费 | 特黄特黄a级毛片免费专区 av网站免费在线观看 | 亚洲成人动漫在线观看 | av网站观看 | 超碰伊人 |