PHP based on DOM implementation of reading the book XML format data of the method detailed

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.