【问题标题】:Recursively build XML from PSQL Result Set (using PHP)从 PSQL 结果集递归构建 XML(使用 PHP)
【发布时间】:2010-11-09 08:56:22
【问题描述】:

我正在使用以下代码成功构建 XML 文档:

public function build($result) {

    $root = $this->append(new xmlElement('data'));
    $root->append(new xmlElement('collection'));

    while($row = pg_fetch_assoc($result)){

        foreach($row as $fieldname => $fieldvalue){
          $second = $root->append(new xmlElement($fieldname));
          $second->write($fieldvalue);
         // $seconds_child = $second->append(new xmlElement('second child child'));
         // $seconds_child->write("second's child content");
        }
    }
}

我的问题是,递归执行此操作的最佳方法是什么?

【问题讨论】:

    标签: php xml postgresql recursion


    【解决方案1】:
    $current = $root;
    foreach($row as $fieldname => $fieldvalue) {
        $next = $current->append(new xmlElement($fieldname));
        $current->write($fieldvalue);
        $current = $next;
    }
    

    我感觉对象引用重新分配会搞砸;如果它不起作用,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 2021-04-23
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      相关资源
      最近更新 更多