Php 将根节点后的节点和属性添加到Array2XML
我使用的是来自的Array2XML,效果非常好 但是我需要在输出之前添加一些节点。我需要我的结构如下:Php 将根节点后的节点和属性添加到Array2XML,php,xml,nodes,Php,Xml,Nodes,我使用的是来自的Array2XML,效果非常好 但是我需要在输出之前添加一些节点。我需要我的结构如下: <clients> <client> -->Need to add <id>myid</id> -->Need to add <name>name</name> -->Need to add <items>
<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>
我试过了,但没用
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;
}
如何在项目循环之前添加此节点和属性
非常感谢 好吧,我搔了搔头才弄到的 我只需要编辑以下内容:
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$clients = $xml->createElement("clients");
$xml->appendChild($clients);
$client = $xml->createElement("client");
$clients->appendChild($client);
$id = $xml->createElement('id', 'myid');
$client->appendChild($id);
$name = $xml->createElement('name', 'myname');
$client->appendChild($name);
$client->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();
$clients = $xml->createElement("clients");
$xml->appendChild($clients);
$client = $xml->createElement("client");
$clients->appendChild($client);
$id = $xml->createElement('id', 'myid');
$client->appendChild($id);
$name = $xml->createElement('name', 'myname');
$client->appendChild($name);
$client->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();
$clients = $xml->createElement("clients");
$xml->appendChild($clients);
$client = $xml->createElement("client");
$clients->appendChild($client);
$id = $xml->createElement('id', 'myid');
$client->appendChild($id);
$name = $xml->createElement('name', 'myname');
$client->appendChild($name);
$client->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}