Introduction
XML parsing is a very important aspect of web development, is allowing to work with structured data in XML format efficiently with more readable and undertandable.
In this lesson We’ll explore main XML parsers in PHP: SimpleXML parsers , DOMDocument parsers , and XMLReader.
By the end of this lesson, we’ll have a good understanding of how to use parse XML documents and how to extract and manipulate data from XML files easily.
XML is standfor:Extensible Markup Language.
XML is a markup language that defines a set of rules for encoding documents in a format to be human-readable.
XML was designed to be flexible,extensible and suitable for representing a wide variety of data structures.
It is Markup Language:
It uses tags to define elements in a document like HTML.
It allows users to define their own special tags,so it is very esaily to represent the structured data.
XML has Hierarchical Structure:
XML documents are organized in a hierarchical structure with nested elements.
Each element can contain text, attributes, and other elements, allowing for the representation of complex data relationships.
XML has Self-Descriptive:
XML documents can contain both data and metadata, with self-descriptive.
Metadata, such as element names and attributes, give additional information about the structure and meaning of the data.
XML is Platform-Independent:
XML is platform-independent so it can be used across different operating systems and programming languages without confilect.
This makes it a popular choice for interchange of data and interoperability between different systems.
XML has Extensibility:
It allows users to define their own tags and document structures using Document Type Definitions (DTD) or XML Schema Definitions (XSD).
XML is commonly used for a variety of purposes, including:
Representing structured data:
XML is used in Representing structured data documents, such as configuration files, data interchange formats, and web services.
Storing and exchanging data:
It is used to sorte and exchange date between different software applications and systems.
It Provids a format for data presentation and transformation in applications like RSS feeds, SVG graphics, and XHTML web pages.
XML provides a flexible and standardized way to represent and exchange structured data, making it a fundamental technology in many areas of computing and information management.
In PHP, there are several ways to parse XML data.
Here are some commonly used XML parsers in PHP:
THe SimpleXML is a PHP extension that provides a simple and easy-to-use interface for working with XML data.
SimpleXML allows us to easily traverse XML documents and access elements and attributes using object-oriented syntax.
For Example:
$xml = simplexml_load_file('data.xml'); foreach ($xml->children() as $child) { echo $child->getName() . ': ' . $child . '<br>'; }
DOMDocument built-in PHP class:
The DOMDocument is a built-in PHP class for working with XML documents in a DOM (Document Object Model) tree structure.
The DOMDocument built-in PHP class allows to manipulate XML documents by creating, modifying, or deleting elements and attributes.
For Example:
$doc = new DOMDocument(); $doc->load('data.xml'); $elements = $doc->getElementsByTagName('element'); foreach ($elements as $element) { echo $element->nodeName . ': ' . $element->nodeValue . '<br>'; }
The XMLReader is a PHP extension that provides a streaming, pull-based interface for reading XML documents.
XMLReader allows to efficiently and easily to parse large XML files without loading the entire document into memory.
For Example:
$reader = new XMLReader(); $reader->open('data.xml'); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'element') { $reader->read(); // move to element value echo $reader->name . ': ' . $reader->value . '<br>'; } } $reader->close();
These are some of the commonly used XML parsers in PHP, each with its own advantages and use cases.
Depending on The requirements and the structure of XML data, we can choose the most suitable parser for wer needs.
Tree-based parsers are XML parsers that construct a tree representation of the XML document in memory.
The Tree-Based Parsers structure allows easy navigation and manipulation of the XML data.
Here are two commonly used tree-based XML parsers in PHP:
Example about The SimpleXML:
The SimpleXML is a PHP extension that gives a simple and intuitive API for working with XML documents as a tree of objects.
The SimpleXML allows us to easily traverse the XML tree and access elements and attributes using object-oriented syntax.
For Example:
$xml = simplexml_load_file('data.xml'); // Accessing elements and attributes echo $xml->element->subelement['attribute'];
DOMDocument is a built-in PHP class for working with XML documents in a DOM (Document Object Model) tree structure.
It gives a set of methods for creating, traversing, and manipulating XML documents and nodes.
For example:
$doc = new DOMDocument(); $doc->load('data.xml'); // Accessing elements and attributes $element = $doc->getElementsByTagName('element')->item(0); $subelement = $element->getElementsByTagName('subelement')->item(0); echo $subelement->getAttribute('attribute');
complete code example with explanation
We will create a simple web page that loads an XML file and displays its contents using both SimpleXML and DOMDocument parsers.
Here’s a step-by-step guide:
Create an XML File:
First, let’s create a sample XML file named data.xml with some sample data:
<?xml version="1.0" encoding="UTF-8"?> <data> <element> <subelement attribute="value1">Subelement 1</subelement> <subelement attribute="value2">Subelement 2</subelement> </element> </data>
Create the PHP Script:
Now, let’s create a PHP script named index.php that loads the XML file using both SimpleXML and DOMDocument parsers and displays its contents:
<!DOCTYPE html> <html> <head> <title>XML Parsing Example</title> </head> <body> <h1>XML Parsing Example</h1> <?php // Load XML file using SimpleXML $xmlSimple = simplexml_load_file('data.xml'); echo '<h2>Using SimpleXML:</h2>'; foreach ($xmlSimple->element->subelement as $subelement) { echo 'Attribute: ' . $subelement['attribute'] . '<br>'; echo 'Value: ' . $subelement . '<br><br>'; } echo '<hr>'; // Load XML file using DOMDocument $doc = new DOMDocument(); $doc->load('data.xml'); echo '<h2>Using DOMDocument:</h2>'; $elements = $doc->getElementsByTagName('element')->item(0)->getElementsByTagName('subelement'); foreach ($elements as $subelement) { echo 'Attribute: ' . $subelement->getAttribute('attribute') . '<br>'; echo 'Value: ' . $subelement->nodeValue . '<br><br>'; } ?> </body> </html>
Explanation:
Run the Script:
Place both data.xml and index.php files in wer web server’s root directory and access index.php through wer web browser. we should see the parsed XML data displayed on the webpage.
This example showshow to parse an XML file using both SimpleXML and DOMDocument parsers in PHP and display the contents on a web page.
Here’s a step-by-step guide on how to use tree-based XML parsers in PHP, specifically SimpleXML and DOMDocument:
1. Set up wer XML file:
First, we need an XML file to parse. Let’s create a simple XML file named data.xml:
<?xml version="1.0" encoding="UTF-8"?> <root> <person> <name>Omar Abobaker</name> <age>20</age> <gender>Male</gender> </person> <person> <name>Gogo AboBaker</name> <age>17</age> <gender>Female</gender> </person> </root>
2. Set up wer PHP script:
Create a PHP script (e.g., parser.php) to parse the XML file using both SimpleXML and DOMDocument:
<?php // Load XML file using SimpleXML $xmlSimple = simplexml_load_file('data.xml'); // Access data using SimpleXML echo "<h2>Using SimpleXML:</h2>"; foreach ($xmlSimple->person as $person) { echo "Name: " . $person->name . "<br>"; echo "Age: " . $person->age . "<br>"; echo "Gender: " . $person->gender . "<br><br>"; } // Load XML file using DOMDocument $doc = new DOMDocument(); $doc->load('data.xml'); // Access data using DOMDocument echo "<h2>Using DOMDocument:</h2>"; $persons = $doc->getElementsByTagName('person'); foreach ($persons as $person) { $name = $person->getElementsByTagName('name')->item(0)->nodeValue; $age = $person->getElementsByTagName('age')->item(0)->nodeValue; $gender = $person->getElementsByTagName('gender')->item(0)->nodeValue; echo "Name: $name <br>"; echo "Age: $age <br>"; echo "Gender: $gender <br><br>"; } ?>
3. Run the script:
Place both data.xml and parser.php files in a web server’s root directory.
Then, access parser.php through web browser.
we should see the parsed XML data displayed on the webpage.
Explanation:
Step 1: We create an XML file data.xml with some sample data about persons.
Step 2: In parser.php, we first load the XML file using SimpleXML (simplexml_load_file) and DOMDocument (DOMDocument::load).
Step 3: With SimpleXML, we use a foreach loop to iterate over each <person> element and access its child elements (<name>, <age>, <gender>) using object properties.
Step 4: With DOMDocument, we use getElementsByTagName to retrieve all <person> elements, and then we access their child elements (<name>, <age>, <gender>) using getElementsByTagName again, and retrieve the node values.
That’s it! we’ve successfully used tree-based parsers to parse XML data in PHP.
Let’s create a complete PHP application that parses an XML file containing information about books using tree-based parsers (SimpleXML and DOMDocument). We’ll display the parsed data on a web page.
Step 1: Set up the XML File
Create an XML file named books.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?> <library> <book> <title>Harry Potter and the Sorcerer's Stone</title> <author>J.K. Rowling</author> <genre>Fantasy</genre> <year>1997</year> </book> <book> <title>To Kill a Mockingbird</title> <author>Harper Lee</author> <genre>Classic</genre> <year>1960</year> </book> </library>
Step 2: Create the PHP Script
Create a PHP script named index.php:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Book Library</title> </head> <body> <h1>Book Library</h1> <?php // Using SimpleXML $xml = simplexml_load_file('books.xml'); echo '<h2>Using SimpleXML:</h2>'; foreach ($xml->book as $book) { echo "<b>Title:</b> $book->title <br>"; echo "<b>Author:</b> $book->author <br>"; echo "<b>Genre:</b> $book->genre <br>"; echo "<b>Year:</b> $book->year <br><br>"; } echo '<hr>'; // Using DOMDocument $doc = new DOMDocument(); $doc->load('books.xml'); echo '<h2>Using DOMDocument:</h2>'; $books = $doc->getElementsByTagName('book'); foreach ($books as $book) { $title = $book->getElementsByTagName('title')->item(0)->nodeValue; $author = $book->getElementsByTagName('author')->item(0)->nodeValue; $genre = $book->getElementsByTagName('genre')->item(0)->nodeValue; $year = $book->getElementsByTagName('year')->item(0)->nodeValue; echo "<b>Title:</b> $title <br>"; echo "<b>Author:</b> $author <br>"; echo "<b>Genre:</b> $genre <br>"; echo "<b>Year:</b> $year <br><br>"; } ?> </body> </html>
Step 3: Run the Application
Place books.xml and index.php files in wer web server’s root directory.
Then, access index.php through wer web browser.
we should see the parsed XML data displayed on the webpage.
Explanation:
Step 1: We created an XML file named books.xml containing information about books.
Step 2: In index.php, we used both SimpleXML and DOMDocument to parse the XML file.
With SimpleXML, we used a foreach loop to iterate over each <book> element and access its child elements directly.
With DOMDocument, we used getElementsByTagName to retrieve all <book> elements and then accessed their child elements using getElementsByTagName again.
Step 3: We ran the application by accessing index.php through a web browser, and the parsed XML data was displayed on the webpage.
That’s it! we’ve successfully created a PHP application that parses an XML file using tree-based parsers and displays the parsed data on a web page.
Event-based parsers, unlike tree-based parsers, do not construct a complete in-memory representation of the XML document. Instead, they generate events as they encounter different parts of the XML document. These parsers are often used for large XML files because they consume less memory compared to tree-based parsers. In PHP, one commonly used event-based XML parser is XMLReader.
Here’s a step-by-step guide on how to use the XMLReader in PHP:
Step 1: Set up wer XML file
Create an XML file named data.xml with the following content:
<?xml version="1.0"?> <root> <person> <name>John Doe</name> <age>30</age> <gender>Male</gender> </person> <person> <name>Jane Smith</name> <age>25</age> <gender>Female</gender> </person> </root>
Step 2: Create the PHP Script
Create a PHP script named parser.php:
<?php // Create a new XMLReader object $xmlReader = new XMLReader(); // Open the XML file $xmlReader->open('data.xml'); // Read through the XML document while ($xmlReader->read()) { // Check if the current node is an element if ($xmlReader->nodeType == XMLReader::ELEMENT) { // Check if the element is <person> if ($xmlReader->name == 'person') { // Read the person's details $name = ''; $age = ''; $gender = ''; while ($xmlReader->read()) { if ($xmlReader->nodeType == XMLReader::ELEMENT) { switch ($xmlReader->name) { case 'name': $name = $xmlReader->readString(); break; case 'age': $age = $xmlReader->readString(); break; case 'gender': $gender = $xmlReader->readString(); break; } } // Break loop when reaching the end of <person> element if ($xmlReader->nodeType == XMLReader::END_ELEMENT && $xmlReader->name == 'person') { break; } } // Output person's details echo "Name: $name<br>"; echo "Age: $age<br>"; echo "Gender: $gender<br><br>"; } } } // Close the XMLReader $xmlReader->close(); ?>
Step 3: Run the Script
Place data.xml and parser.php files in a web server’s root directory.
Then, access parser.php through wer web browser. we should see the parsed XML data displayed on the webpage.
Explanation:
Step 1: We created an XML file named data.xml containing information about persons.
Step 2: In parser.php, we created an XMLReader object and opened the XML file.
Step 3: We then read through the XML document and extracted information about each <person> element encountered. As we encounter each <person> element, we extract the data within it (name, age, gender) and output it.
Step 4: Finally, we close the XMLReader.
That’s it! we’ve successfully created a PHP application that parses an XML file using an event-based parser (XMLReader) and displays the parsed data on a web page.
Below is a step-by-step guide to creating a complete PHP application that uses the XMLReader, an event-based XML parser, to parse an XML file containing information about books. We’ll then display this parsed data on a web page.
Step 1: Set up the XML File
Create an XML file named books.xml with the following content:
<?xml version="1.0"?> <library> <book> <title>Harry Potter and the Sorcerer's Stone</title> <author>J.K. Rowling</author> <genre>Fantasy</genre> <year>1997</year> </book> <book> <title>To Kill a Mockingbird</title> <author>Harper Lee</author> <genre>Classic</genre> <year>1960</year> </book> </library>
Step 2: Create the PHP Script
Create a PHP script named parser.php:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Book Library</title> </head> <body> <h1>Book Library</h1> <?php // Create a new XMLReader object $xmlReader = new XMLReader(); // Open the XML file $xmlReader->open('books.xml'); // Read through the XML document while ($xmlReader->read()) { // Check if the current node is an element and the element is <book> if ($xmlReader->nodeType == XMLReader::ELEMENT && $xmlReader->name == 'book') { $title = ''; $author = ''; $genre = ''; $year = ''; // Read until the end of the current <book> element while ($xmlReader->read() && $xmlReader->name != 'book') { // Check if the current node is an element if ($xmlReader->nodeType == XMLReader::ELEMENT) { switch ($xmlReader->name) { case 'title': $title = $xmlReader->readString(); break; case 'author': $author = $xmlReader->readString(); break; case 'genre': $genre = $xmlReader->readString(); break; case 'year': $year = $xmlReader->readString(); break; } } } // Output book details echo "<b>Title:</b> $title <br>"; echo "<b>Author:</b> $author <br>"; echo "<b>Genre:</b> $genre <br>"; echo "<b>Year:</b> $year <br><br>"; } } // Close the XMLReader $xmlReader->close(); ?> </body> </html>
Step 3: Run the Application
Place books.xml and parser.php files in wer web server’s root directory. Then, access parser.php through wer web browser. we should see the parsed XML data displayed on the webpage.
Explanation:
Step 1: We created an XML file named books.xml containing information about books.
Step 2: In parser.php, we created an XMLReader object and opened the XML file.
Step 3: We then read through the XML document. For each <book> element encountered, we extract its child elements (<title>, <author>, <genre>, <year>) using the XMLReader and output their values.
Step 4: Finally, we closed the XMLReader.
That’s it! we’ve successfully created a PHP application that parses an XML file using an event-based parser (XMLReader) and displays the parsed data on a web page.
Let’s create a complete PHP project that shows the use of different XML parsers:
SimpleXML, DOMDocument, and XMLReader.
This project will read an XML file containing information about books and display this data on a web page.
Step 1: Set Up the Project Structure
Create a directory named xml-parser-project and create the following files within it:
index.php: The main PHP script that will display the parsed XML data.
books.xml: An XML file containing information about books.
style.css (Optional): A CSS file to style the output HTML.
Step 2: Populate the books.xml File
Create an XML file named books.xml with the following content:
<?xml version="1.0"?> <library> <book> <title>Harry Potter and the Sorcerer's Stone</title> <author>J.K. Rowling</author> <genre>Fantasy</genre> <year>1997</year> </book> <book> <title>To Kill a Mockingbird</title> <author>Harper Lee</author> <genre>Classic</genre> <year>1960</year> </book> </library>
Step 3: Create the index.php File
Create a PHP script named index.php:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Book Library</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Book Library</h1> <?php // Load XML file using SimpleXML $xmlSimple = simplexml_load_file('books.xml'); // Display using SimpleXML echo '<div class="parser-box">'; echo '<h2>Using SimpleXML:</h2>'; foreach ($xmlSimple->book as $book) { echo "<div class='book'>"; echo "<b>Title:</b> $book->title <br>"; echo "<b>Author:</b> $book->author <br>"; echo "<b>Genre:</b> $book->genre <br>"; echo "<b>Year:</b> $book->year <br>"; echo "</div>"; } echo '</div>'; // Load XML file using DOMDocument $doc = new DOMDocument(); $doc->load('books.xml'); // Display using DOMDocument echo '<div class="parser-box">'; echo '<h2>Using DOMDocument:</h2>'; $books = $doc->getElementsByTagName('book'); foreach ($books as $book) { $title = $book->getElementsByTagName('title')->item(0)->nodeValue; $author = $book->getElementsByTagName('author')->item(0)->nodeValue; $genre = $book->getElementsByTagName('genre')->item(0)->nodeValue; $year = $book->getElementsByTagName('year')->item(0)->nodeValue; echo "<div class='book'>"; echo "<b>Title:</b> $title <br>"; echo "<b>Author:</b> $author <br>"; echo "<b>Genre:</b> $genre <br>"; echo "<b>Year:</b> $year <br>"; echo "</div>"; } echo '</div>'; // Load XML file using XMLReader $xmlReader = new XMLReader(); $xmlReader->open('books.xml'); // Display using XMLReader echo '<div class="parser-box">'; echo '<h2>Using XMLReader:</h2>'; while ($xmlReader->read()) { if ($xmlReader->nodeType == XMLReader::ELEMENT && $xmlReader->name == 'book') { $book = new SimpleXMLElement($xmlReader->readOuterXml()); echo "<div class='book'>"; echo "<b>Title:</b> $book->title <br>"; echo "<b>Author:</b> $book->author <br>"; echo "<b>Genre:</b> $book->genre <br>"; echo "<b>Year:</b> $book->year <br>"; echo "</div>"; } } $xmlReader->close(); echo '</div>'; ?> </body> </html>
Step 4: Create the style.css File (Optional)
we can create a CSS file named style.css to style the output HTML as per wer preference.
Step 5: Run the Project
Place all the files (index.php, books.xml, style.css) in the xml-parser-project directory within wer web server’s root directory. Then, access index.php through wer web browser. we should see the parsed XML data displayed on the webpage, organized by each parser.
Explanation:
Step 1: We created a project directory and set up the necessary files (index.php, books.xml, style.css).
Step 2: The books.xml file contains information about books in XML format.
Step 3: In index.php, we used SimpleXML, DOMDocument, and XMLReader to parse the XML file and display the book details on the webpage. Each parser is enclosed within its own <div> container with a corresponding heading.
Step 4: Optionally, we can style the output HTML using the style.css file.
Step 5: After running the project, we should see the parsed XML data displayed on the webpage, organized by each parser.
That’s it! we’ve successfully created a PHP project demonstrating the use of different XML parsers to parse an XML file and display the data on a web page.
Let’s create another PHP project that shows the use of XML parsers.
In this project, we’ll parse an XML file containing information about movies and display the data in a tabular format on a web page.
We’ll use SimpleXML and DOMDocument for parsing.
Step 1: Set Up the Project Structure
Create a directory named movie-parser-project and create the following files within it:
index.php: The main PHP script that will display the parsed XML data.
movies.xml: An XML file containing information about movies.
Step 2: Populate the movies.xml File
Create an XML file named movies.xml with the following content:
<?xml version="1.0"?> <movies> <movie> <title>The Shawshank Redemption</title> <director>Frank Darabont</director> <genre>Drama</genre> <year>1994</year> </movie> <movie> <title>The Godfather</title> <director>Francis Ford Coppola</director> <genre>Crime</genre> <year>1972</year> </movie> </movies>
Step 3: Create the index.php File
Create a PHP script named index.php:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Movie Library</title> <style> table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <h1>Movie Library</h1> <?php // Load XML file using SimpleXML $xmlSimple = simplexml_load_file('movies.xml'); // Display using SimpleXML echo '<h2>Using SimpleXML:</h2>'; echo '<table>'; echo '<tr><th>Title</th><th>Director</th><th>Genre</th><th>Year</th></tr>'; foreach ($xmlSimple->movie as $movie) { echo '<tr>'; echo "<td>{$movie->title}</td>"; echo "<td>{$movie->director}</td>"; echo "<td>{$movie->genre}</td>"; echo "<td>{$movie->year}</td>"; echo '</tr>'; } echo '</table>'; // Load XML file using DOMDocument $doc = new DOMDocument(); $doc->load('movies.xml'); // Display using DOMDocument echo '<h2>Using DOMDocument:</h2>'; echo '<table>'; echo '<tr><th>Title</th><th>Director</th><th>Genre</th><th>Year</th></tr>'; $movies = $doc->getElementsByTagName('movie'); foreach ($movies as $movie) { $title = $movie->getElementsByTagName('title')->item(0)->nodeValue; $director = $movie->getElementsByTagName('director')->item(0)->nodeValue; $genre = $movie->getElementsByTagName('genre')->item(0)->nodeValue; $year = $movie->getElementsByTagName('year')->item(0)->nodeValue; echo '<tr>'; echo "<td>$title</td>"; echo "<td>$director</td>"; echo "<td>$genre</td>"; echo "<td>$year</td>"; echo '</tr>'; } echo '</table>'; ?> </body> </html>
Step 4: Run the Project
Place all the files (index.php and movies.xml) in the movie-parser-project directory within wer web server’s root directory. Then, access index.php through wer web browser. we should see the parsed XML data displayed in a tabular format on the webpage, using both SimpleXML and DOMDocument parsers.
Explanation:
Step 1: We created a project directory and set up the necessary files (index.php and movies.xml).
Step 2: The movies.xml file contains information about movies in XML format.
Step 3: In index.php, we used SimpleXML and DOMDocument to parse the XML file and display movie details in a tabular format on the webpage.
Step 4: After running the project, we should see the parsed XML data displayed in a tabular format on the webpage, using both SimpleXML and DOMDocument parsers.
That’s it! we’ve successfully created a PHP project demonstrating the use of XML parsers to parse an XML file and display the data on a web page.
A) To create XML documents from scratch.
B) To parse XML documents and extract data.
C) To validate XML documents against a schema.
D) To transform XML documents into other formats.
A) XMLReader
B) SimpleXML
C) DOMDocument
D) SAXParser
A) Event-based parsers are simpler to use.
B) Event-based parsers consume less memory.
C) Event-based parsers offer better performance for small XML files.
D) Event-based parsers provide better support for XPath queries.
A) simplexml_parse_file()
B) simplexml_load_string()
C) simplexml_load_file()
D) simplexml_create()
A) Document Object Model
B) Data Object Model
C) Document Output Module
D) Data Output Module
Explanation:
Answer: B) To parse XML documents and extract data.
XML parsers in PHP are used to parse XML documents and extract data for further processing or manipulation.
Answer: C) DOMDocument
DOMDocument is a tree-based XML parser in PHP that constructs an in-memory tree representation of the XML document.
Answer: B) Event-based parsers consume less memory.
Event-based parsers like XMLReader consume less memory compared to tree-based parsers, making them suitable for large XML files.
Answer: C) simplexml_load_file()
simplexml_load_file() is the PHP function used to load an XML file into SimpleXML.
Answer: A) Document Object Model
In the context of XML parsing in PHP, DOM stands for Document Object Model. It represents the structure of an XML document as a tree of objects.
These questions cover the basics of XML parsers in PHP, including their purpose, types, and usage.