PHP Tutorial
Advanced PHP
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- PHP - Coding Standard
- PHP - File Uploading
- PHP - Sending Emails
- PHP - Sessions
- PHP - Cookies
- PHP - Functions
- PHP - Files & I/O
- PHP - File Inclusion
- PHP - GET & POST
- PHP - Web Concepts
- PHP - Strings
- PHP - Arrays
- PHP - Loop Types
- PHP - Decision Making
- PHP - Operator Types
- PHP - Constants
- PHP - Variable Types
- PHP - Syntax Overview
- PHP - Environment Setup
- PHP - Introduction
- PHP - Home
Advanced PHP
- PHP - For PERL Developers
- PHP - For C Developers
- PHP - Object Oriented
- PHP & XML
- PHP & AJAX
- PHP & MySQL
- PHP - Date & Time
- PHP - Bugs Debugging
- PHP - Error Handling
- PHP - Regular Expression
- PHP - Predefined Variables
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
- PHP - DOM Parser Example
- PHP - SAX Parser Example
- PHP - Simple XML GET
- PHP - Simple XML
- PHP - XML Introduction
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PHP - Simple XML GET
PHP - Simple XML GET
XML Get has used to get the node values from xml file. The following example shows, How to get the data from xml.
Note.xml
Note.xml is xml file, It can accessed by php file.
<SUBJECT> <COURSE>Android</COURSE> <COUNTRY>India</COUNTRY> <COMPANY>TutorialsPoint</COMPANY> <PRICE>$10</PRICE> </SUBJECT>
Index.htm
Index page has rights to get access the xml data by using implexml_load_file().
<?php $xml = simplexml_load_file("note.xml") or die("Error: Object Creation failure"); ?> <html> <head> <body> <?php echo $xml->COURSE . "<br>"; echo $xml->COUNTRY . "<br>"; echo $xml->COMPANY . "<br>"; echo $xml->PRICE; ?> </body> </head> </html>
It will produce the following result −
Get Node Values
The below code is having information about how to get node values from xml file and XML should be as follows −
<?xml version = "1.0" encoding = "utf-8"?> <tutorialspoint> <course category = "JAVA"> <title lang = "en">Java</title> <tutor>Gopal</tutor> <duration></duration> <price>$30</price> </course> <course category = "HADOOP"> <title lang = "en">Hadoop</title>. <tutor>Satish</tutor> <duration>3>/duration> <price>$50</price> </course> <course category = "HTML"> <title lang = "en">html</title> <tutor>raju</tutor> <duration>5</duration> <price>$50</price> </course> <course category = "WEB"> <title lang = "en">Web Technologies</title> <tutor>Javed</tutor> <duration>10</duration> <price>$60</price> </course> </tutorialspoint>
PHP code should be as follows
<html> <body> <?php $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object"); foreach($xml->children() as $books) { echo $books->title . "<br> "; echo $books->tutor . "<br> "; echo $books->duration . "<br> "; echo $books->price . "<hr>"; } ?> </body> </html>
It will produce the following result −
Advertisements