PHP XML DOM Parser

the XML dom parser is called tree-based parser which transform an xml document into a tree structure. using it we can easily work with xml nodes (element, attributes).

this below xml file will be used in our examples:

              // demo.xml

     <?xml    version="1.0"    encoding= "utf-8" ?>
     
        <software>
           
               <item  type = "microchip">
               
                    <name>sata23</name>
                    
                      <price>1234.1234</price>
                        
                         <quantity>220333</quantity>
                         
               </item>
               
        </software>

load xml

first we create an xml dom object using domdocument() method

the php load() method is used to loads an xml document.

      <?php  
                $xdoc = new domdocument();
                
                $xdoc->load( "soft.xml");
                
                print $xdoc->savexml();
                
      ?>

the output of the code above:

sata23 1234.1234 220333