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.
This is my xml file format and file name is readxml.xml file
<?xml version="1.0"?> <!-- our XML-document describes a purchase order --> <purchase-order> <date>2005-10-31</date> <number>12345</number> <purchased-by> <name>My name</name> <address>My address</address> </purchased-by> <!-- a collection element, contains a set of items --> <order-items> <item> <code>687</code> <type>CD</type> <label>Some music</label> </item> <item> <code>129851</code> <type>DVD</type> <label>Some video</label> </item> </order-items> </purchase-order>
This is one php file called test.php and code as follows
<?php
//create new document object
$dom_object = new DOMDocument();
//load xml file
$dom_object->load("test.xml");
$item = $dom_object->getElementsByTagName("item");
foreach( $item as $value )
{
$codes = $value->getElementsByTagName("code");
$code = $codes->item(0)->nodeValue;
$types = $value->getElementsByTagName("type");
$type = $types->item(0)->nodeValue;
$labels = $value->getElementsByTagName("label");
$label = $labels->item(0)->nodeValue;
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
Incoming search terms:
- xml logo
- xml icon
- wordpress parse xml
- reed files wordpress api
- add_meta_box button read xml file
- xml reader plugin wordpress
- xml reading in wordpress
- parse xml wordpress
- XML logo file
- wordpress read xml
- php parsing an xml with same labels
- php read file like wordpress
- php read wordpress xml file
- php read xml file -simplexml
- php xml data on wordpress
- wordpress xml file parse
- to read xml feeds using wordpress
- using wordpress to display xml
- wordpress read from xml
- wordpress read xml file and store






Pingback: How to read xml using php | wordpressapi.com » WB Tips
Nice post and we all totally agree with the author on this view right here. Its crazy, that is what i can say concerning this. Because this should be what the whole life is all about right? Keep on doing a great job!
I just like the valuable information you provide on your articles. I will bookmark your weblog and check again here regularly. I’m reasonably sure I will be told many new stuff proper right here! Best of luck for the following!
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?