Summary of PHP methods for outputting XML format data

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

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.