How to display XML data in web page using PHP ? Last Updated : 31 Mar, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we are going to display data present in an XML file on a web page using PHP through the XAMPP server. PHP is a server-side scripting language that is mainly for processing web data. The XML stands for an extensible markup language. Requirements: XAMPP server Syntax: <root> <child> <subchild>.....</subchild> </child> </root> Approach: We are going to use mainly two functions in our PHP code. The simplexml_load_file() function is used to convert an XML document to an object. simplexml_load_file simplexml_load_file(name of XML file) children(): The children() function finds the children of a specified node. $xml_data->children() Steps to execute: Step 1: Start XAMPP server. Open notepad and type the following codes in xml_data.xml and code.php formats The xml_data.xml: Consider student XML data as an example. xml_data.xml <?xml version = "1.0" encoding = "utf-8"?> <collegedata> <department category = "IT"> <subjects lang = "en">java</subjects> <name>G.Sravan Kumar</name> <age>22</age> <marks>98</marks> <address>guntur</address> </department> <department category = "CSE"> <subjects lang = "en">Python</subjects> <name>B. Naga sudheer</name> <age>28</age> <marks>96</marks> <address>guntur</address> </department> <department category = "IT"> <subjects lang = "en">sql</subjects> <name>Radha</name> <age>25</age> <marks>78</marks> <address>guntur</address> </department> </collegedata> Step 3:The following is the code for code.php file. code.php <?php // Start php code // Load xml file into xml_data variable $xml_data = simplexml_load_file("xml_data.xml") or die("Error: Object Creation failure"); // Use foreach loop to display data and for sub elements access, // We will use children() function foreach ($xml_data->children() as $data) { //display each sub element in xml file echo "Subject name : ", $data->subjects . "<br> "; echo "Student name : ", $data->name . "<br> "; echo "Student age : ", $data->age . "<br> "; echo "Student marks : ", $data->marks . "<br>"; echo "Student address : ", $data->address . "<br>"; echo "------------------------------------"; echo "<br>"; } ?> Step 4: Save these two files in xampp/htdocs/geek folder. The developer can use any other folder instead of geek folder. Output: Open your browser and type localhost/geek/code.php to see the output. XML data Comment More infoAdvertise with us Next Article How to display XML data in web page using PHP ? sravankumar_171fa07058 Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-XML PHP-Questions +1 More Similar Reads How to Display Data from CSV file using PHP ? We have given the data in CSV file format and the task is to display the CSV file data into the web browser using PHP. To display the data from CSV file to web browser, we will use fgetcsv() function. Comma Separated Value (CSV) is a text file containing data contents. It is a comma-separated value 2 min read How to convert XML file into array in PHP? Given an XML document and the task is to convert an XML file into PHP array. To convert the XML document into PHP array, some PHP functions are used which are listed below: file_get_contents() function: The file_get_contents() function is used to read a file as string. This function uses memory mapp 2 min read Web Scraping in PHP Using Simple HTML DOM Parser Web Scraping is a technique used to extract large amounts of data from websites extracted and saved them to a local file in your computer or to a database or can be used as API. Data displayed by most websites can be viewed by using a web browser only. They do not offer the functionality to save a c 2 min read How to fetch data from localserver database and display on HTML table using PHP ? In this article, we will see how we can display the records in an HTML table by fetching them from the MySQL database using PHP. Approach: Make sure you have XAMPP or WAMP server installed on your machine. In this article, we will be using the WAMP server. WAMP Server is open-source software for th 4 min read How to connect the Database with PHP DOM page ? In this article, we will see how to connect the database with the PHP DOM page? Approach: Make sure you have XAMPP or WAMP installed on your machine. In this tutorial, we will be using the XAMPP server. To connect the database with the PHP DOM page, follow the steps given below: 1. Create Database: 3 min read How to Export data to CSV file from Database using XAMPP ? In this article, we are going to load the data present in the database (MySQL) into CSV file. Display the data in the database and also export that data into CSV file. We are using XAMPP tool to store locally in a database. XAMPP stands for  cross-platform, Apache, MySQL, PHP, and Perl. It is among 3 min read PHP program to fetch data from localhost server database using XAMPP In this article, we will see how we can display the records by fetching them from the MySQL database using PHP. Approach: Make sure you have an XAMPP server or WAMP server installed on your machine. In this article, we will be using the XAMPP server.XAMPP is a free and open-source cross-platform web 4 min read PHP code to store XML data into CSV In this article, we are going to store XML data into a CSV file using PHPH. XML stands for an extensible markup language. XML is similar to HTML but whereas in HTML, we can't define our own tags, but in XML we can define our own tags. Requirements: XAMPP Server. Structure of XML: <root> <ch 3 min read How to get return text from PHP file with ajax ? In this article, we will see how to get return the text from the PHP file with ajax. Ajax is an acronym for Asynchronous JavaScript and XML is a series of web development techniques that build asynchronous web applications using many web technologies on the client-side. Without reloading the web pag 2 min read How to echo HTML in PHP ? While making a web application with PHP, we often need to print or echo few results in form of HTML. We can do this task in many different ways. Some of methods are described here: Using echo or print: PHP echo or print can be used to display HTML markup, javascript, text or variables. Example 1: Th 2 min read Like