This article mainly introduces the php xml Parsing method and analyzes the related skills of php XML parsing in the form of examples. if you need it, refer to the following article to introduce the php xml Parsing method, detailed analysis of php XML parsing skills in the form of examples. For more information, see
This document describes in detail the xml Parsing method in php as an example. Share it with you for your reference. The specific analysis is as follows:
The books. xml file is as follows:
Harry Potter J K. Rowling
2005
29.99
Everyday Italian Giada De Laurentiis
2005
30.00
Learning XML Erik T. Ray
2003
39.95
1. DOM parsing XML
Load ("books. xml "); // get all book Tags $ bookDom = $ doc-> getElementsByTagName (" book "); foreach ($ bookDom as $ book) {$ title = $ book-> getElementsByTagName ("title")-> item (0)-> nodeValue; $ author = $ book-> getElementsByTagName ("author ") -> item (0)-> nodeValue; $ year = $ book-> getElementsByTagName ("year")-> item (0)-> nodeValue; $ price = $ book-> getElementsByTagName ("price")-> item (0)-> nodeValue; echo "title :". $ title."
"; Echo" author: ". $ author ."
"; Echo" year: ". $ year ."
"; Echo" price: ". $ price ."
"; Echo "***********************************
";}?>
2. xml_parse_into_struct
Create a parser, parse the xml data to the array, release the parser, and then extract the desired value from the array.
"; Print_r ($ arr); echo"
";?>
3. use the SAX parser to read the XML-----XML Simple API (SAX) parser
"; print_r($xml); echo "
";?>
The above is a detailed description of the php parsing xml method example (with code). For more information, see other related articles in the first PHP community!