Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did just this a while ago, I can't see exactly whats going wrong. But I can provide the function I built for a site for you to look at.<br> This function worked 100% fine and as expected. It created a perfect XML document and formatted it perfectly. I hope this helps you find your problem.</p> <pre><code>function create_xml_file() { /* create a dom document with encoding utf8 */ $domtree = new DOMDocument('1.0', 'utf-8'); /* create the root element of the xml tree */ /* Data Node */ $xmlRoot = $domtree-&gt;createElement("data"); /* append it to the document created */ $xmlRoot = $domtree-&gt;appendChild($xmlRoot); /* Set our Prices in our &lt;data&gt; &lt;config&gt; node */ $config_node = $domtree-&gt;createElement("config"); $config_node = $xmlRoot-&gt;appendChild($config_node); // Add - node to config $config_node-&gt;appendChild($domtree-&gt;createElement('config_node', '123456')); $config_node-&gt;appendChild($domtree-&gt;createElement('some_other_data', '123456')); /* Create prices Node */ $price_node = $domtree-&gt;createElement('price'); $price_node = $config_node-&gt;appendChild($price_node); /* Black Price Node */ $black_node = $price_node-&gt;appendChild($domtree-&gt;createElement('black')); foreach ($p-&gt;List_all() as $item): if ($item['color'] == 'black'): $black_node-&gt;appendChild($domtree-&gt;createElement($item['type'], $item['price'])); endif; endforeach; /* Create galleries Node */ $galleries_node = $domtree-&gt;createElement("galleries"); $galleries_node = $xmlRoot-&gt;appendChild($galleries_node); foreach ($i-&gt;List_all() as $image): /* Our Individual Gallery Node */ $gallery_node = $domtree-&gt;createElement("gallery"); $gallery_node = $galleries_node-&gt;appendChild($gallery_node); $gallery_node-&gt;appendChild($domtree-&gt;createElement('name', $image['name'])); $gallery_node-&gt;appendChild($domtree-&gt;createElement('filepath', $image['filepath'])); $gallery_node-&gt;appendChild($domtree-&gt;createElement('thumb', $image['thumb'])); endforeach; /* Format it so it is human readable */ $domtree-&gt;preserveWhiteSpace = false; $domtree-&gt;formatOutput = true; /* get the xml printed */ //echo $domtree-&gt;saveXML(); $file = 'xml/config.xml'; $domtree-&gt;save($file); } </code></pre> <p><strong>I hope this helps you find your answer. I commented it well for easy understanding.</strong></p>
    singulars
    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. VO
      singulars
      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