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
PHP - Simple XML
The simple XML parser
The simple XML parser is used to parse Name, attributes and textual content.
The simple XML functions are shown below −
simplexml_load_file()
This function accepts file path as a first parameter and it is mandatory.
simplexml_load_file(($fileName,$class,$options,$ns,$is_prefix)
simplexml_load_string()
This function accepts the string instead of file reference.
simplexml_load_string($XMLData,$class,$options,$ns,$is_prefix)
simplexml_import_dom()
This function accepts DOM formatted XML content and it converts into simple XML.
simplexml_load_string($DOMNode,$class)
The following example shows, How to parse a xml data file.
<?php $data = "<?xml version = 1.0 encoding = UTF-8 ?> <note> <Course>Android</Course> <Subject>Android</Subject> <Company>TutorialsPoint</Company> <Price>$10</Price> </note>"; $xml = simplexml_load_string($data) or die("Error: Cannot create object"); ?> <html> <head> <body> <?php print_r($xml); ?> </body> </head> </html>
It will produce the following result −
SimpleXMLElement Object ( [Course] => Android [Subject] => Android [Company] => TutorialsPoint [Price] => $10 )
We can also call a xml data file as shown below and it produces the same result as shown above −
<?php $xml = simplexml_load_file("data") or die("Error: Cannot create object"); print_r($xml); ?>Advertisements