Go deep into three methods for php to output xml to the page content

Source: Internet
Author: User
Go deep into three methods for php to output xml to the page content

  1. Header ("Content-type: text/xml ");
  2. Echo" ";
  3. Echo" ";
  4. Echo" ";
  5. Echo" ";
  6. Echo "";
  7. Echo"";
  8. Echo "";
  9. Echo "24 ";
  10. Echo"";
  11. Echo" ";
  12. Echo "male ";
  13. Echo"";
  14. Echo"";
  15. Echo" ";
  16. Echo" ";
  17. Echo "Yan ";
  18. Echo"";
  19. Echo "";
  20. Echo "23 ";
  21. Echo"";
  22. Echo" ";
  23. Echo "female ";
  24. Echo"";
  25. Echo"";
  26. Echo"";
  27. ?>

Method 2,

  1. Header ("Content-type: text/xml ");
  2. Echo" ";
  3. Echo" Cainiao 24 Male Yan 23 Female ";
  4. ?>

Method 3,

  1. /*

  2. Use the php dom control to create XML output
  3. Set the output content type to xml
  4. Edit bbs.it-home.org
  5. */
  6. Header ('content-Type: text/xml ;');
  7. // Create a new xml file
  8. $ Dom = new DOMDocument ('1. 0', 'utf-8 ');

  9. // Create Element

  10. $ Response = $ dom-> createElement ('response ');
  11. $ Dom-> appendChild ($ response );

  12. // Create Element and use it Child element

  13. $ Books = $ dom-> createElement ('books ');
  14. $ Response-> appendChild ($ books );

  15. // Create a title for the book

  16. $ Title = $ dom-> createElement ('title ');
  17. $ TitleText = $ dom-> createTextNode ('php and AJAX ');
  18. $ Title-> appendChild ($ titleText );

  19. // Create an isbn element for the book

  20. $ Isbn = $ dom-> createElement ('isbn ');
  21. $ IsbnText = $ dom-> createTextNode ('1-21258986 ');
  22. $ Isbn-> appendChild ($ isbnText );

  23. // Create a book element

  24. $ Book = $ dom-> createElement ('book ');
  25. $ Book-> appendChild ($ title );
  26. $ Book-> appendChild ($ isbn );

  27. // Set As Child element

  28. $ Books-> appendChild ($ book );

  29. // Create an XML structure in a string variable

  30. $ XmlString = $ dom-> saveXML ();

  31. // Output an XML string

  32. Echo $ xmlString;
  33. ?>

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.