我正在尝试将xml传递给使用cakephp 2.3.0构建的其余API,并且我收到错误但我使用了cakephp 1.3。我想知道问题是否与cakephp的XML核心实用程序有关。
发布的XML字符串如下
<?xml version="1.0" encoding="UTF-8"?>
<username>my username</username>
<password>mypassword</password>
<name>Namanya Hillary</name>
<title>mytitle</title>
错误如下
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}
我尝试直接在实用程序文件夹中的核心XML实用程序文件中传递XML,如第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);
但正在提出同样的例外。如果你遇到这样的问题,或者你看到任何错误,请帮助我。解决方案的参考链接将非常有用。在此先感谢。
答案 0 :(得分:4)
正确形成的XML必须具有单个根元素。你没有那个。尝试将请求格式设置为:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<username>my username</username>
<password>mypassword</password>
<name>Namanya Hillary</name>
<title>mytitle</title>
</request>