i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
DOM parser is another tree-based parser that is used to parse XML documents. This parser functions need to be installed as they are part of PHP core. The XML line Joy will be parsed by DOM as a tree structure in below way:
Level1: XML document
Level2: Root element:
Level 3: Text element: “Joy”
Let us take the same example of Reminder.xml for XML DOM parser.
$xmlDom = new DOMDocument();
$xmlDom->load("Reminder.xml");
print $xmlDom->saveXML();
?>
The above PHP code initialize, load the XML and output it as below:
Lindsi Sebastian Reminder Send me an update this weekend!
You can also loop through all elements of the note element we created in the starting of the XML code. It will initialize, load and loop through all elements.
$xmlDom = new DOMDocument();
$xmlDom->load("Reminder.xml");
$data = $xmlDom->documentElement;
foreach ($data->childNodes AS $item) {
print $item->nodeName . " = " . $item->nodeValue . "
";
}
?>
Output of above code will be:
#text =
to = Lindsi
#text =
from = Sebastian
#text =
heading = Reminder
#text =
body = Send me an update this weekend!
#text =
In above example, there are few empty text nodes because, when XML generates, it creates white spaces between nodes and DOM treats them as normal elements that can sometime become an issue if you are not aware of them.
Don't miss out!