【发布时间】:2017-04-25 18:27:48
【问题描述】:
我正在使用来自this link 的 Array2XML,效果很好!
但我需要在输出之前添加一些节点。我需要我的结构是这样的:
<clients>
<client> -->Need to add
<id>myid</id> -->Need to add
<name>name</name> -->Need to add
<items> -->Need to add
<item>
<title>itemtitle</title>
<date>itemdate</date>
</item>
</items>
</client>
<clients>
但我能得到的只有:
<clients>
<item>
<title>itemtitle</title>
<date>itemdate</date>
</item>
<clients>
ROOT NODE clients 和节点item 可以输出,但是如何在节点item 之前添加节点client 和属性id、name 和子节点items?
这是我想我需要进行更改的 php 函数,但没有成功:
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$xml->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}
我试过了,但是不行……
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$clientname='client';
$client = $xml->createElement($clientname);
$xml->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}
如何在项目循环之前添加此节点和属性?
非常感谢!
【问题讨论】: