


Detailed explanation of how PHP reads book XML format data based on DOM
May 26, 2018 am 11:26 AMThis article mainly introduces the method of using PHP to read book XML format data based on DOM. It involves PHP's DOM-based reading operation for XML format files. Friends in need can refer to the following
for details. As follows:
<?php $doc = new DOMDocument(); $doc->load( 'books.xml' ); $books = $doc->getElementsByTagName( "book" ); foreach( $books as $book ) { $authors = $book->getElementsByTagName( "author" ); $author = $authors->item(0)->nodeValue; $publishers = $book->getElementsByTagName( "publisher" ); $publisher = $publishers->item(0)->nodeValue; $titles = $book->getElementsByTagName( "title" ); $title = $titles->item(0)->nodeValue; echo "$title - $author - $publisher\n"; } ?>
books.xml file is as follows:
<?xml version="1.0"?> <books> <book> <author>Jack Herrington</author> <title>PHP Hacks</title> <publisher>O'Reilly</publisher> </book> <book> <author>Jack Herrington</author> <title>Podcasting Hacks</title> <publisher>O'Reilly</publisher> </book> </books>
The running results are as follows:
PHP Hacks - Jack Herrington - O'Reilly Podcasting Hacks - Jack Herrington - O'Reilly
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP implementation of reading XML format file
php implements the calculation formula of string format through eval
##A brief analysis of the difference between json and jsonp and obtaining json data through ajax PostFormat Conversion
The above is the detailed content of Detailed explanation of how PHP reads book XML format data based on DOM. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
