Many new PHP developer looking for how to easily read the xml file. In this tutorial I will show you how to read the xml file using PHP language. Here I given the sample code for parsing the XML using PHP.
How to read xml using php

This is my xml file format and file name is readxml.xml file
06 | < date >2005-10-31</ date > |
07 | < number >12345</ number > |
11 | < address >My address</ address > |
20 | < label >Some music</ label > |
26 | < label >Some video</ label > |
This is one php file called test.php and code as follows
03 | $dom_object = new DOMDocument(); |
05 | $dom_object ->load( "test.xml" ); |
07 | $item = $dom_object ->getElementsByTagName( "item" ); |
09 | foreach ( $item as $value ) |
11 | $codes = $value ->getElementsByTagName( "code" ); |
12 | $code = $codes ->item(0)->nodeValue; |
14 | $types = $value ->getElementsByTagName( "type" ); |
15 | $type = $types ->item(0)->nodeValue; |
17 | $labels = $value ->getElementsByTagName( "label" ); |
18 | $label = $labels ->item(0)->nodeValue; |
20 | echo "$code - $type - $label <br>" ; |
When you run the readxml.php file. you will see the following output.
687 – CD – Some music
129851 – DVD – Some video
How Can I get XML information from an specific URL with variables, I am working in my travel agency web page and my wholesaler provider give me the catalog in a xml url source and I am doing the web page in WordPress.. Can you help me?
Cannot thank you enough for this!!!
This saved me an untold amount of time!
You rock!