XML is the acronym for Extensible Markup Language. XML is used to structure, store and transport data from one system to another. It uses opening and closing tags.
There are two major types of XML parsers in php
1. Tree-Based Parsers - Example of tree-based parsers are SimpleXML and DOM
2. Event-Based Parsers - Example of event-based parsers are XMLReader and XML Expat Parser
Create XML parse as per below code.
<?php
$file = "xml_beginner.xml";
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "";
}
function endTag($parser, $data){
echo "
";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
$xmldata = new SimpleXMLElement($data);
print_r($xmldata);
xml_parser_free($xml_parser);
fclose($fp);
?>
The PHP simplexml_load_string() function is used to read XML data from a string.
- Home
- PHP
Search
PHP Tutorial
- Email Validation using JS Script & PHP Integration
- PHP MCQs - 1
- PHP MCQs - 2
- PHP MCQs - 3
- PHP MCQs - 4
- PHP MCQs - 5
- PHP MCQs - 6
- PHP MCQs - 7
- PHP MCQs - 8
- PHP MCQs - 9
- PHP MCQs - 10
- Learn Tutorial for What is PHP?
- Learn PHP Syntax
- Learn PHP Variable
- Learn Session Management using php
- Learn PHP interface in OOPs
- Learn How to parse xml using php
- what is difference between php4 and php5?
- Learn How to Install PHP
- Learn PHP Echo Statement
- Learn PHP String Functions
- php cookies
- PHP session
- PHP if..else..else if Statements
- PHP Switch
- PHP For Loop
- PHP foreach loop
- PHP While Loop
- PHP do while loop
- PHP Break
- PHP continue
- PHP Print
- PHP Comments
- PHP $ and $$ Variables
- PHP Constants
- PHP Magic Constants
- PHP Data Types
- PHP Arrays
- PHP Include and Require
- PHP POST and GET Method
- PHP File Handling
- PHP File Upload
- PHP header
- PHP Error Handling
- PHP Error Types
- PHP Sending Emails
- PHP Sending HTML email
- PHP Sending attachments with email
- PHP Functions
- PHP - What is OOP?
- PHP oops - What is Class?
- PHP oops - What is Object?
- PHP oops - Access Modifiers
- PHP oops - Constructor
- PHP oops - Destructor
- PHP oops - $this Keyword
- PHP oops - Abstract class
- PHP OOPs - Interfaces
- PHP OOPs - Interfaces vs. Abstract Classes
- PHP OOPs - Inheritance
- PHP OOPs - Method Overriding
- PHP OOPs - The final Keyword
- PHP oops - Method Overloading
- PHP oops - Magic Method
- How to integrate simple PHP CAPTCHA script?
- How to import large Dump mysql database file for mysql?
- PHP Exception Handling
- php code to validate phone number
- php code to validate email address
- PHP Interview Questions
- What is the difference between POST and GET?
- php time
- PHP NULL
- PHP cURL
- PHP Date
- PHP round
- how to download and install wamp server?
- Online PHP Compiler
- PHP Captcha
PHP - Related Asked Questions
- how can i solve php header errors?
- Write a PHP function to check if a given string is a palindrome
- Create a PHP function to count the number of vowels in a string.
- Write a PHP function that throws a custom exception if a condition is not met.
- Create a PHP script that uses sessions to store and display user information.
- Write a PHP script that connects to a MySQL database and fetches data from a table.
- Create a PHP script that processes a form submission and displays the submitted data.
- How to prevent SQL Injection using php
- Write a PHP script that parses JSON data and displays specific information.
- Write a PHP script that sets a cookie with user preferences and retrieves it on subsequent visits.
- Create a simple PHP script that calculates the sum of all even numbers between 1 and 10.
- Write a PHP script that generates and displays a simple multiplication table for the numbers 1 to 5.
- Create a PHP script that checks whether a given number is a prime number or not.
- Write a PHP script that generates and displays a list of the first 10 Fibonacci numbers.
- Create a PHP script that prints the current date and time.
- Write a PHP script that calculates the factorial of a given number.
- How to reverses a given string using PHP.
- How to get the largest element in an array of numbers
- Create a PHP script that counts the number of occurrences of each word in a given sentence.
- Write a PHP script that calculates the sum of digits in a given number.
- How to check whether a given year is a leap year using php.
- Write a PHP script that generates a random password of a specified length.
- Create a PHP script that calculates and displays the area of a rectangle given its length and width.
- Write a PHP script that checks if a given string is a valid email address.
- Create a PHP script that calculates the average of an array of numbers.
- How to convert a temperature from Celsius to Fahrenheit using php.
- How to check if a given number is a perfect number.
- Write a PHP script that calculates the factorial of a given number using an iterative approach.
- how to get country, state and city select option using google map api in php
- how to get current lat and lng from ip address using google map api in php?
- how to get current latitude and longitude using google map api in php?
- How to call travelport catalogproductofferings api using php?
- how to get response status in api using curl php?
- How to show location using google map in JavaScript?
- what is PhpUnit?
RECENT POSTS
Recent Asked Questions
- Create a PHP script that uses sessions to store and display user information.
- How to use Vue Router for navigation?
- Write to function to calculate the factorial of a number
- How to convert Celsius to Fahrenheit using node js
- Explain Vue.js directives like v-bind and v-on.
- Write a PHP script that calculates the sum of digits in a given number.
Web Tutorials
- PHP Compiler
- Node.js Compiler
- Java Compiler
- AngularJS
- AWS
- C
- C Interview Questions
- Centos Server
- Codeigniter
- Computer engineering
- CPP
- CPP Interview Questions
- CSS
- HTML
- JAVA
- Java Interview Questions
- Laravel
- Linux server
- MongoDB
- MYSQL
- Node js
- Node js Interview Questions
- PHP
- PHP Functions
- PHP Interview Questions
- PHP Programs
- React JS
- Vue
- Wordpress
Comments