This article mainly introduces PHP based on the DOM implementation of reading the book XML format data, involving PHP based on the DOM for XML file read operation related skills, the need for friends can refer to the following
Specific 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)->nod Evalue; $publishers = $book->getelementsbytagname ("publisher"); $publisher = $publishers->item (0)->nodevalue; $titles = $book->getelementsbytagname ("title"); $title = $titles->item (0)->nodevalue; echo "$title-$author-$publisher \ n"; }?>
The 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 results of the operation are as follows:
PHP hacks-jack herrington-o ' reillypodcasting hacks-jack herrington-o ' Reilly
The above is the whole content of this article, I hope that everyone's study has helped.