Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting content of a XML file using XML DOM
    primarykey
    data
    text
    <p>I have a simple XML document:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;cellphones&gt; &lt;telefon&gt; &lt;model&gt;Easy DB&lt;/model&gt; &lt;proizvodjac&gt;Alcatel&lt;/proizvodjac&gt; &lt;cena&gt;25&lt;/cena&gt; &lt;/telefon&gt; &lt;telefon&gt; &lt;model&gt;3310&lt;/model&gt; &lt;proizvodjac&gt;Nokia&lt;/proizvodjac&gt; &lt;cena&gt;30&lt;/cena&gt; &lt;/telefon&gt; &lt;telefon&gt; &lt;model&gt;GF768&lt;/model&gt; &lt;proizvodjac&gt;Ericsson&lt;/proizvodjac&gt; &lt;cena&gt;15&lt;/cena&gt; &lt;/telefon&gt; &lt;telefon&gt; &lt;model&gt;Skeleton&lt;/model&gt; &lt;proizvodjac&gt;Panasonic&lt;/proizvodjac&gt; &lt;cena&gt;45&lt;/cena&gt; &lt;/telefon&gt; &lt;telefon&gt; &lt;model&gt;Earl&lt;/model&gt; &lt;proizvodjac&gt;Sharp&lt;/proizvodjac&gt; &lt;cena&gt;60&lt;/cena&gt; &lt;/telefon&gt; &lt;/cellphones&gt; </code></pre> <p>I need to print the content of this file using XML DOM, and it needs to be structured like this: </p> <pre><code>"model: Easy DB proizvodjac: Alcatel cena: 25" </code></pre> <p>for each node inside the XML.</p> <p>IT HAS TO BE DONE using XML DOM. That's the problem. I can do it the usual, simple way. But this one bothers me because I can't seem to find any solution on the internet. </p> <p>This is as far as I can go, but I need to access inside nodes (child nodes) and to get node values. I also want to get rid of some weird string "#text" that comes up out of the blue.</p> <pre><code>&lt;?php //kreira se DOMDocument objekat $xmlDoc = new DOMDocument(); //u xml objekat se ucitava xml fajl $xmlDoc-&gt;load("poruke.xml"); //dodeljuje se promenljivoj koreni element $x = $xmlDoc-&gt;documentElement; //prolazi se kroz petlju tako sto se ispisuje informacija o podelementima foreach ($x-&gt;childNodes AS $item){ print $item-&gt;nodeName . " = " . $item-&gt;nodeValue . "&lt;br /&gt;"; } ?&gt; </code></pre> <p>Thanks</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.
 

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