Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将根节点后的节点和属性添加到Array2XML_Php_Xml_Nodes - Fatal编程技术网

Php 将根节点后的节点和属性添加到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>

我使用的是来自的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>
我试过了,但没用

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;
}