Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Solved the problem, I noticed, to solve the problem of setting the position of the child whether to be inside the parent or to be another parent and have child:</p> <pre><code> $node[0] = $xmlDoc-&gt;createElement('message'); $xmlDoc-&gt;appendChild($node[0]); $node[1] = $xmlDoc-&gt;createElement('document'); $node[0]-&gt;appendChild($node[1]); $node[2] = $xmlDoc-&gt;createElement('dtl'); $node[0]-&gt;appendChild($node[2]); </code></pre> <p>set the:</p> <pre><code>$node[X] = $xmlDoc-&gt;createElement('node_name'); //create the element $node[Y]-&gt;appendchild($node[X]); // append or insert the $node[$X] to that node if using create element in node X it will produce a child, if createAttribute, it will add attributes into the node. </code></pre> <p>and the code to make the required xml to be dynamically generated:</p> <pre><code> $xmlDoc = new DOMDocument('1.0'); $xmlDoc-&gt;formatOutput = true; $root_name = ""; $node = array(); $node_ctr = "1"; for($a=0;$a&lt;count($res_detail);$a++): { /* GET ROOT NODE */ if($res_detail[$a]-&gt;MWSCDRoot == "1"): { $node[0] = $xmlDoc-&gt;createElement($res_detail[$a]-&gt;MWSCDValue); $xmlDoc-&gt;appendChild($node[0]); for($b=0;$b&lt;count($res_detail);$b++): { /* GET ROOT ATTRIBUTE IF ANY */ if($res_detail[$b]-&gt;MWSCDAttribute == "1"): { $attr = $xmlDoc-&gt;createAttribute($res_detail[$b]-&gt;MWSCDValue); $attr-&gt;value = $this-&gt;xml_functions-&gt;get_value($res_detail[$b]-&gt;MWSCDID,$res_detail,$res_user); $node[0]-&gt;appendChild($attr); } endif; } endfor; } endif; if(!empty($node[0])): { if($res_detail[$a]-&gt;MWSCDParent == "1"): { $node[$node_ctr] = $xmlDoc-&gt;createElement($res_detail[$a]-&gt;MWSCDValue); $node[0]-&gt;appendChild($node[$node_ctr]); $node_ctr++; for($x=0;$x&lt;count($res_detail);$x++): { if($res_detail[$x]-&gt;MWSCDAttribute == $node_ctr): { $attr = $xmlDoc-&gt;createAttribute($res_detail[$x]-&gt;MWSCDValue); $attr-&gt;value = $this-&gt;xml_functions-&gt;get_value($res_detail[$x]-&gt;MWSCDID,$res_detail,$res_user); $node[1]-&gt;appendChild($attr); } endif; } endfor; } elseif($res_detail[$a]-&gt;MWSCDParent &lt;&gt; "1" &amp;&amp; !empty($res_detail[$a]-&gt;MWSCDParent)): { $node[$node_ctr] = $xmlDoc-&gt;createElement($res_detail[$a]-&gt;MWSCDValue); $node[$node_ctr-1]-&gt;appendChild($node[$node_ctr]); $node_ctr++; for($x=0;$x&lt;count($res_detail);$x++): { if($res_detail[$x]-&gt;MWSCDAttribute == $node_ctr): { $attr = $xmlDoc-&gt;createAttribute($res_detail[$x]-&gt;MWSCDValue); $attr-&gt;value = $this-&gt;xml_functions-&gt;get_value($res_detail[$x]-&gt;MWSCDID,$res_detail,$res_user); $node[$node_ctr-1]-&gt;appendChild($attr); } endif; } endfor; } endif; } endif; } endfor; </code></pre> <p>OUTPUT:</p> <pre><code>&lt;message password="Password" userid="TestUser"&gt; &lt;document merchantid="" docdefinition=""&gt; &lt;dtl ref5="" custid="" refid="" filldate="" ref1="" ref2="" ref3="" ref4=""&gt; &lt;/dtl&gt; &lt;/document&gt; &lt;/message&gt; </code></pre> <p>*ADDITIONAL NOTE: I had to ORDER BY the column in the query to make it work</p> <pre><code> ORDER BY `merchantwsconfigdetail`.`MWSCDRoot` DESC, `merchantwsconfigdetail`.`MWSCDisParent` DESC, `merchantwsconfigdetail`.`MWSCDParent` DESC, `merchantwsconfigdetail`.`MWSCDNode` ASC, `merchantwsconfigdetail`.`MWSCDAttribute` ASC </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload