1
我使用的是this link的Array2XML,它工作的很棒!将根节点后的节点和属性添加到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>
根节点clients
和节点item
我能输出,但我怎么可以添加节点client
和atributes id
,name
,以及节点item
之前的子节点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;
}
如何在项目循环之前添加此节点和属性?
非常感谢!