This article mainly introduces the PHP method for outputting XML format data, and summarizes and analyzes the common xml format data output related operations in php based on the instance form, for more information about how to output XML format data in PHP, see the next article. This article summarizes and analyzes the common xml format data output operations in php based on examples, for more information, see
This example describes how PHP outputs XML format data. We will share this with you for your reference. The details are as follows:
Method 1:
"; Echo"
"; Echo"
"; Echo"
"; Echo" "; echo"
"; Echo" "; echo" 24 "; echo""; Echo"
"; Echo" male "; echo"
"; Echo"
"; Echo"
"; Echo"
"; Echo" Yan "; echo"
"; Echo" "; echo" 23 "; echo""; Echo"
"; Echo" female "; echo"
"; Echo"
"; Echo"
";?>
The preceding example is run as follows:
Method 2:
"; Echo"
Cainiao
24
Male
</User>
Yan
23 </age>
Female
";?>
Method 3:
Element $ response = $ dom-> createElement ('response'); $ dom-> a ($ response); // Create
Element and use it
Child Element $ books = $ dom-> createElement ('books '); $ response-> a ($ books ); // create the title $ title = $ dom-> createElement ('title') for the book; $ titleText = $ dom-> createTextNode ('php and AJAX '); $ title-> a ($ titleText); // Create an isbn element for the book $ isbn = $ dom-> createElement ('isbn '); $ isbnText = $ dom-> createTextNode ('1-21258986 '); $ isbn-> a ($ isbnText ); // create the book element $ book = $ dom-> createElement ('book'); $ book-> a ($ title); $ book-> a ($ isbn ); // Set
As
Child Element $ books-> a ($ book); // Create an XML structure in a string variable $ xmlString = $ dom-> saveXML (); // output the XML string echo $ xmlString;?>
1. php output xml instance
header('Content-Type: text/xml');$sql = "select * from article order by post_date limit 100";$re = $db->query($sql);echo "
\n";echo "\n";while($row = $db->fetchArray($re)){echo "
";echo htmlspecialchars($row['content']);echo "
\n";}echo "";
2. use JavaScript to operate XML instances
Try to use all the operations and attributes for demonstration.