How to Extract Data from an XML File Using PHP ?
Last Updated :
24 Apr, 2025
XML, which stands for Extensible Markup Language, is a data storage format that is easily searchable and understandable. It simplifies the process of storing, retrieving, and displaying data in informative applications. It is widely used in web applications. In this article, we will learn how to extract data from an XML file using the PHP programming language.
Sample XML File
Below mentioned XML file contains data about Books. It has all the information that is required by a reader about a book such as author, title, price, genre, etc.
XML
<?xml version="1.0"?>
<catalog>
<book id="wd101">
<author>Smith, John</author>
<title>Mastering HTML5</title>
<genre>Web Development</genre>
<price>34.99</price>
<publish_date>2022-03-15</publish_date>
<description>
A comprehensive guide to mastering the
latest features of HTML5 for web development.
</description>
</book>
<book id="wd102">
<author>Williams, Sarah</author>
<title>Responsive Web Design Techniques</title>
<genre>Web Development</genre>
<price>28.95</price>
<publish_date>2021-09-20</publish_date>
<description>
Explore effective techniques for creating
responsive and mobile-friendly web designs.
</description>
</book>
<book id="wd103">
<author>Anderson, James</author>
<title>JavaScript Programming Essentials</title>
<genre>Web Development</genre>
<price>22.50</price>
<publish_date>2020-05-08</publish_date>
<description>
Essential concepts and techniques for mastering
JavaScript programming in web development.
</description>
</book>
<book id="wd104">
<author>Roberts, Emily</author>
<title>Full Stack Development with Node.js</title>
<genre>Web Development</genre>
<price>45.99</price>
<publish_date>2019-11-12</publish_date>
<description>
A comprehensive guide to full-stack web
development using Node.js, Express, and MongoDB.
</description>
</book>
<book id="wd105">
<author>Chang, Li</author>
<title>Modern CSS Frameworks</title>
<genre>Web Development</genre>
<price>19.95</price>
<publish_date>2018-06-25</publish_date>
<description>
Learn to leverage the power of modern CSS frameworks
for efficient and stylish web development.
</description>
</book>
</catalog>