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

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

WBOY
WBOYOriginal
2016-07-25 09:10:46785browse
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


Statement:
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