Three ways to drill down into PHP output XML to page content

Source: Internet
Author: User
    1. Header ("Content-type:text/xml");
    2. echo " ";
    3. echo " ";
    4. echo " ";
    5. echo " ";
    6. echo "Little rookie";
    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 Yan";
    18. echo "";
    19. echo "";
    20. echo "23";
    21. echo "";
    22. echo " ";
    23. echo "female";
    24. echo "";
    25. echo "";
    26. echo "";
    27. ?>
Copy Code

Method 2,

    1. Header ("Content-type:text/xml");
    2. echo " ";
    3. echo "The Little rookie , the man , the gorgeous girl ";
    4. ?>
Copy Code

Method 3,

  1. /*

  2. Use PHP's 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. Building Elements

  10. $response = $dom->createelement (' response ');
  11. $dom->appendchild ($response);

  12. A child element that creates an element and takes it as a

  13. $books = $dom->createelement (' books ');
  14. $response->appendchild ($books);

  15. Create a title for book

  16. $title = $dom->createelement (' title ');
  17. $titleText = $dom->createtextnode (' PHP and Ajax ');
  18. $title->appendchild ($titleText);

  19. Create an ISBN element for book

  20. $ISBN = $dom->createelement (' ISBN ');
  21. $isbnText = $dom->createtextnode (' 1-21258986 ');
  22. $ISBN->appendchild ($isbnText);

  23. Create book Element

  24. $book = $dom->createelement (' book ');
  25. $book->appendchild ($title);
  26. $book->appendchild ($ISBN);

  27. Will act as a child element

  28. $books->appendchild ($book);

  29. Building an XML structure in a string variable

  30. $xmlString = $dom->savexml ();

  31. Output XML string

  32. Echo $xmlString;
  33. ?>

Copy Code
  • Related Article

    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.