KMART240777
Backend System Visionary
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial we will create a Simple Load XML Data using PHP. This code can display XML file into a readable HTML table. The code use simplexml_load_file to call a block of data within the xml file when the user click the button. This is a user-friendly kind of program feel free to modify it.
We will be using XML as a markup language that utilize in php as a HTML data. It is designed to store and transport data that can be manipulated within the local server.
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
Creating the Main Function
This code contains the main function of the application. This code will load and display a xml data when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as shown below.
data.xml
xml version="1.0"?
John Smith
Male
I
B
Claire
Temple
I
A
load_xml.php
There you have it we successfully created Simple Load XML Data using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
We will be using XML as a markup language that utilize in php as a HTML data. It is designed to store and transport data that can be manipulated within the local server.
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class = "navbar navbar-default">
- <div class = "container-fluid">
- <a class = "navbar-brand" href = "https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class = "col-md-3"></div>
- <div class = "col-md-6 well">
- <h3 class = "text-primary">PHP - Simple Load XML Data</h3>
- <hr style = "border-top:1px dotted #000;" />
- <form method="POST">
- <button name="load" class="btn btn-primary"><span class="glyphicon glyphicon-book"></span> Load XML</button>
- </form>
- <br /><br />
- <?php
include
'load_xml.php'
?>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will load and display a xml data when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as shown below.
data.xml
xml version="1.0"?
John Smith
Male
I
B
Claire
Temple
I
A
load_xml.php
- <?php
- if
(
ISSET
(
$_POST
[
'load'
]
)
)
{
- ?>
- <table class="table table-bordered" >
- <thead class="alert-info">
- <tr>
- <th>Name</th>
- <th>Gender</th>
- <th>Year</th>
- <th>Section</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $xml
=
simplexml_load_file
(
'data.xml'
)
;
- foreach
(
$xml
->
student
as
$student
)
{
- echo
'
- <tr>
- <td>'
.
$student
->
name
.
'</td>
- <td>'
.
$student
->
gender
.
'</td>
- <td>'
.
$student
->
year
.
'</td>
- <td>'
.
$student
->
section
.
'</td>
- </tr>
- '
;
- }
- ?>
- </tbody>
- </table>
- <?php
- }
else
{
- ?>
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>Name</th>
- <th>Gender</th>
- <th>Year</th>
- <th>Section</th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- <?php
- }
- ?>
There you have it we successfully created Simple Load XML Data using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
You must upgrade your account or reply in the thread to view the hidden content.