1:
<? PHP
Header ("Content-Type: text/XML ");
Echo "<? XML version =/"1.0/" encoding =/"UTF-8/"?> ";
Echo "<users> ";
Echo "<user> ";
Echo "<Name> ";
Echo "";
Echo "</Name> ";
Echo "<age> ";
Echo "24 ";
Echo "</age> ";
Echo "<sex> ";
Echo "male ";
Echo "</sex> ";
Echo "</user> ";
Echo "<user> ";
Echo "<Name> ";
Echo "Yan ";
Echo "</Name> ";
Echo "<age> ";
Echo "23 ";
Echo "</age> ";
Echo "<sex> ";
Echo "female ";
Echo "</sex> ";
Echo "</user> ";
Echo "</users> ";
?>
2:
<? PHP
Header ("Content-Type: text/XML ");
Echo "<? XML version =/"1.0/" encoding =/"UTF-8/"?> ";
Echo "<users> <user> <Name> ainiao </Name> <age> 24 </age> <sex> male </sex> </user> <user> <Name> Yan </Name> <age> 23 </age> <sex> female </sex> </user> </users> ";
?>
3:
<? PHP
/*
Use the PHP Dom control to create XML output
Set the output content type to XML
*/
Header ('content-type: text/XML ;');
// Create a New XML file
$ Dom = new domdocument ('1. 0', 'utf-8 ');
// Create the <response> element
$ Response = $ dom-> createelement ('response ');
$ Dom-> appendchild ($ response );
// Create the <books> element and use it as the sub-element of <response>
$ 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 );
// Use <book> as a sub-element of <books>
$ Books-> appendchild ($ book );
// Create an XML structure in a string variable
$ Xmlstring = $ dom-> savexml ();
// Output an XML string
Echo $ xmlstring;
?>