Go deep into three methods for php to output xml to the page content
- Header ("Content-type: text/xml ");
- Echo" ";
- 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"";
- ?>
Method 2,
- Header ("Content-type: text/xml ");
- Echo" ";
- Echo" Cainiao 24 Male Yan 23 Female ";
- ?>
Method 3,
/*
- Use the php dom control to create XML output
- Set the output content type to xml
- Edit bbs.it-home.org
- */
- Header ('content-Type: text/xml ;');
- // Create a new xml file
- $ Dom = new DOMDocument ('1. 0', 'utf-8 ');
// Create Element
- $ Response = $ dom-> createElement ('response ');
- $ Dom-> appendChild ($ response );
// Create Element and use it Child element
- $ Books = $ dom-> createElement ('books ');
- $ Response-> appendChild ($ books );
// Create a title for the book
- $ Title = $ dom-> createElement ('title ');
- $ TitleText = $ dom-> createTextNode ('php and AJAX ');
- $ Title-> appendChild ($ titleText );
// Create an isbn element for the book
- $ Isbn = $ dom-> createElement ('isbn ');
- $ IsbnText = $ dom-> createTextNode ('1-21258986 ');
- $ Isbn-> appendChild ($ isbnText );
// Create a book element
- $ Book = $ dom-> createElement ('book ');
- $ Book-> appendChild ($ title );
- $ Book-> appendChild ($ isbn );
// Set As Child element
- $ Books-> appendChild ($ book );
// Create an XML structure in a string variable
- $ XmlString = $ dom-> saveXML ();
// Output an XML string
- Echo $ xmlString;
- ?>
|