【问题标题】:cakephp passing array to Xml::build()cakephp 将数组传递给 XML::build()
【发布时间】:2012-04-24 19:37:21
【问题描述】:

CakePHP 文档说我可以使用 XML::build() 将数组转换为 XML。我得到的只是错误。这是我在#cakephp irc 的帖子。

我有一个multi-dimension data set,为此我创建了一个wrapper function to output my xmlthis message 出错。我做错了什么?

【问题讨论】:

  • 按照建议,我将调用更改为 $xml = Xml::build(array('root' => $_records));。现在我收到错误:警告 (2): SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 3: parser error : Extra content at the end of the document [CORE\Cake\Utility\Xml. php,第 177 行] 字符串无法解析为 XML
  • 添加返回元素删除了警告 $xml = Xml::build(array('return' => 'simplexml', 'root' => $_records));。错误已替换为无效输入。
  • 在单步执行应用程序后,我发现了应用程序炸弹的位置。 bin.cakephp.org/view/403624274。问题是我不知道为什么或如何解决它。
  • 好的,这是另一个尝试。 bin.cakephp.org/view/724808941。输出看起来错误,这可以解释错误。但它并没有解释为什么数组编码不正确。
  • 从那以后我了解到数组的根元素是数字的,并且父元素和子元素实际上是作为该根的子兄弟构造的。绝对不是我想要的。我正在创建这样的数组:$invoices = $this->Invoice->find('all');。没什么特别的,但它让我尝试理解为什么会发生这种情况以及如何解决它。

标签: php xml cakephp multidimensional-array


【解决方案1】:

这是我发现的一个类,它遍历多维php数组并转换为xml。

Convert PHP Array to XML or Simple XML Object if you wish

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多