PHP provides an XML Parser that helps to parse and process XML documents. Here's a brief overview of the PHP XML Parser:
The PHP XML Parser is event-based, meaning that instead of receiving back a tree structure from the XML document, your code will be notified as the parser reads through the document and encounters certain events (e.g., start tags, end tags, text nodes).
To use the XML parser, you'll need to define handlers for these events. Here's a list of handler functions you might use:
Consider this XML:
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Let's parse this XML:
<?php
$parser = xml_parser_create();
// Element handler
function start($parser, $element_name, $element_attrs) {
switch($element_name) {
case "NOTE":
echo "-- New note --<br>";
break;
case "TO":
echo "To: ";
break;
case "FROM":
echo "From: ";
break;
case "HEADING":
echo "Heading: ";
break;
case "BODY":
echo "Message: ";
break;
}
}
function end($parser, $element_name) {
echo "<br>";
}
// Character data handler
function char($parser, $data) {
echo $data;
}
xml_set_element_handler($parser, "start", "end");
xml_set_character_data_handler($parser, "char");
$fp = fopen("note.xml", "r");
while ($data = fread($fp, 4096)) {
xml_parse($parser, $data, feof($fp)) or
die(sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>
Remember that XML tags are case-sensitive, but by default, the PHP XML parser returns all tag names in uppercase.
UPCET Exam
Click Here
SAAT Exam
Click Here
MHT CET Exam
Click Here
IPU CET Exam
Click Here
KCET Exam
Click Here
COMEDK UG Exam
Click Here
VITEEE Exam
Click Here
BITSAT
Click Here
DSAT: Dayanand Sagar Admission Test
Click Here
Career In Animation in india
Click Here
Merchant Navy Courses in india
Click Here
Interior Design Career in india
Click Here
UGC NET Exam
Click Here
B. Ed Exam
Click Here
AFCAT - Air Force Common Admission Test
Click Here
GATE Exam
Click Here
Joint Entrance Examination (JEE)
Click Here
Common Admission Test (CAT)
Click Here
CDS - Combined Defence Services Exam
Click Here