dongtang1944 2013-01-31 07:37
浏览 70
已采纳

cakephp 2.3.0的XML错误稳定

am trying to pass xml to a rest API am building with cakephp 2.3.0 and am getting an error yet i made it work with cakephp 1.3. Am wondering whether the problem is with the XML core utility of cakephp.

The XML string am posting is as below

<?xml version="1.0" encoding="UTF-8"?>
<username>my username</username>
<password>mypassword</password>
<name>Namanya Hillary</name>
<title>mytitle</title>

And the Error is as below

2013-01-31 07:32:25 Error: [Exception] String could not be parsed as XML
#0 E:\wamp\www\cakephp2.3.0\lib\Cake\Utility\Xml.php(131): SimpleXMLElement->__construct('<?xml version="...', 16384)
#1 E:\wamp\www\cakephp2.3.0\lib\Cake\Utility\Xml.php(100): Xml::_loadXml('<?xml version="...', Array)
#2 E:\wamp\www\cakephp2.3.0\lib\Cake\Controller\Component\RequestHandlerComponent.php(222): Xml::build('<?xml version="...')
#3 [internal function]: RequestHandlerComponent->convertXml('<?xml version="...')
#4 E:\wamp\www\cakephp2.3.0\lib\Cake\Network\CakeRequest.php(828): call_user_func_array(Array, Array)
#5 [internal function]: CakeRequest->input(Array)
#6 E:\wamp\www\cakephp2.3.0\lib\Cake\Controller\Component\RequestHandlerComponent.php(207): call_user_func_array(Array, Array)
#7 [internal function]: RequestHandlerComponent->startup(Object(CompaniesController))
#8 E:\wamp\www\cakephp2.3.0\lib\Cake\Utility\ObjectCollection.php(131): call_user_func_array(Array, Array)
#9 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#10 E:\wamp\www\cakephp2.3.0\lib\Cake\Event\CakeEventManager.php(247): call_user_func(Array, Object(CakeEvent))
#11 E:\wamp\www\cakephp2.3.0\lib\Cake\Controller\Controller.php(670): CakeEventManager->dispatch(Object(CakeEvent))
#12 E:\wamp\www\cakephp2.3.0\lib\Cake\Routing\Dispatcher.php(183): Controller->startupProcess()
#13 E:\wamp\www\cakephp2.3.0\lib\Cake\Routing\Dispatcher.php(161): Dispatcher->_invoke(Object(CompaniesController), Object(CakeRequest), Object(CakeResponse))
#14 E:\wamp\www\forex\webroot\index.php(102): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#15 {main}

I tried passing the XML directly in the core XML utility file in the utility folder as below on line 130

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><username>my username</username><password>mypassword</password><name>Namanya Hillary</name><title>mytitle</title>', LIBXML_NOCDATA);

but the same exception is being raised. Please help me if u have encountered such a problem or if u see any mistake made. Reference links to solutions will be useful. Thanks in-advance.

  • 写回答

1条回答 默认 最新

  • donglu8549 2013-01-31 07:42
    关注

    Properly formed XML must have a single root element. You do not have that. Try making the request format something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <request>
        <username>my username</username>
        <password>mypassword</password>
        <name>Namanya Hillary</name>
        <title>mytitle</title>
    </request>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探