DOMDocument->getElementsByTagName() Examples : DOM : XML PHP Source Code


PHP Source Code » XML » DOM »

 

DOMDocument->getElementsByTagName() Examples


<?php
$xml 
=<<<EOT
<?xml version="1.0"?>
<config>
 <section id="section1">
  <param name="param1">value1</param>
  <param name="param2">value2</param>
 </section>
 <section id="section2">
  <param name="param3">value3</param>
 </section>
</config>
EOT;
        
$dom = new DomDocument;
        
$dom->preserveWhiteSpace FALSE;
        
$dom->loadXML($xml);
        
$params $dom->getElementsByTagName('param');
        foreach (
$params as $param) {
              echo 
$param -> getAttribute('name').'
        '
;
        }
?>
Expected result:
--------------
param1
param2
param3 


HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo XML
» DOM