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;
}
如何在項目循環之前添加此節點和屬性?
非常感謝!