Note that there are some explanatory texts on larger screens.

plurals
  1. POSimpleXML writing in PHP
    primarykey
    data
    text
    <p>First of all i have to tell you that i'm absoluetly new to PHP! </p> <p>I want to write into a simple XML file. </p> <p>I have a loop in which if the file does not exists I create the file and add the first child I need:</p> <pre><code>$newFile = simplexml_load_file("myXMLPattern.xml"); $UDID = $newFile-&gt;addChild('UDID'); $valueUDID = $UDID-&gt;addChild('valueUDID',$udidDevice); $dom = new DOMDocument('1.0'); $dom-&gt;preserveWhiteSpace = false; $dom-&gt;formatOutput = true; $dom-&gt;loadXML($newFile-&gt;asXML()); $dom-&gt;saveXML(); $dom-&gt;save("./UDID/".$udidReference.".xml"); </code></pre> <p>Everything is ok, it creates my file and add the child I need! I use DOM to get a format file : </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;iPhone&gt; &lt;UDID&gt; &lt;valueUDID&gt;myValue&lt;/valueUDID&gt; &lt;/UDID&gt; &lt;/iPhone&gt; </code></pre> <p>When the files exists i simply need to add my and child I use: </p> <pre><code>$UDIDFile = simplexml_load_file("./UDID/".$udidReference.".xml"); $UDID = $UDIDFile-&gt;addChild('UDID'); $valueUDID = $UDIDFile-&gt;addChild('valueUDID',$udidDevice); $dom = new DOMDocument('1.0'); $dom-&gt;preserveWhiteSpace = false; $dom-&gt;formatOutput = true; $dom-&gt;loadXML($UDIDFile-&gt;asXML()); $dom-&gt;saveXML(); $dom-&gt;save("./UDID/".$udidReference.".xml"); </code></pre> <p>But the result I get is: </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;iPhone&gt; &lt;UDID&gt; &lt;valueUDID&gt;myValue&lt;/valueUDID&gt; &lt;/UDID&gt; &lt;/UDID&gt; &lt;valueUDID&gt;myNewValue&lt;/valueUDID&gt; &lt;/iPhone&gt; </code></pre> <p>This is not what I want! I simply want to add: </p> <pre><code>&lt;UDID&gt; &lt;valueUDID&gt;myNewValue&lt;/valueUDID&gt; &lt;/UDID&gt; </code></pre> <p>My code simple close the tag <code>&lt;/UDID&gt;</code>, I do not know how to do it!</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.
 

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