Home > Backend Development > PHP Tutorial > Method 1 of php reading xml---DOMDocument reads xml

Method 1 of php reading xml---DOMDocument reads xml

WBOY
Release: 2016-07-25 09:10:46
Original
788 people have browsed it
XML (Extensible Markup Language) is an extensible markup language. Like HTML, it is SGML (Standard Generalized Markup Language, Standard Generalized Markup Language).
  1. xml source file
  2. Zhang Ying
  3. Male
  4. 28
  5. tank
  6. Male
  7. 28
  8. $doc = new DOMDocument();
  9. $doc->load(' person.xml'); //Read xml file
  10. $humans = $doc->getElementsByTagName( "humans" ); //Get the object array of humans tag
  11. foreach( $humans as $human )
  12. {
  13. $names = $human->getElementsByTagName( "name" ); //Get the object array of the tag of name
  14. $name = $names->item(0)->nodeValue; //Get the value in node, Such as
  15. $sexs = $human->getElementsByTagName( "sex" );
  16. $sex = $sexs->item(0)->nodeValue;
  17. $olds = $human->getElementsByTagName( "old" );
  18. $old = $olds->item(0)->nodeValue;
  19. echo "$name - $sex - $oldn";
  20. }
  21. ?> ;
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template