PHP Creating XML documents through Dom _php tutorial

Source: Internet
Author: User
Recently, using the Zendframework framework to do projects, to take the data from the database to generate XML documents. Here's a note about the process:

XML file:

1.

2.

3. Docker JCP1

4. Docker JCP2

5. Docker JCP3

6. Docker JCP4

7. Docker JCP5

8. Docker JCP6

9.

1. Build testcontroller.php and add function.

1. Public Function projectaction () {

1.//xml-related Routine

2.//$list refers to an array of data in the XML.

3. $dom = new DOMDocument (' 1.0 ', ' utf-8 ');

4.//Create root element

5. $root = $dom->createelement ("data");

6. $dom->appendchild ($root);

7.

8.//project name XML List

9. foreach ($list as $project _item) {

//Create child element

$projectname = $dom->createelement (' project ');

$root->appendchild ($projectname);

13.

//Create CDATA section

$cdata = $dom->createcdatasection ($project _item->name);

$projectname->appendchild ($cdata);

17.

$id = $dom->createattribute ("id");

$projectname->appendchild ($id);

20.

//Create attribute value node

$idValue = $dom->createtextnode ($project _item->project_id);

$id->appendchild ($idValue);

24.}

$output = $dom->savexml ();

26.

//Setting up headers and body

$this->_response->setheader (' Content-type ', ' text/xml; Charset=utf-8 ')

->setbody ($output);

$this->_helper->layout->disablelayout ();

31.}

This allows you to output XML on the page.

If you want to save the XML, use $dom->save ("Filename.xml");

This article is from "Bob" blog

http://www.bkjia.com/PHPjc/478702.html www.bkjia.com true http://www.bkjia.com/PHPjc/478702.html techarticle recently, using the Zendframework framework to do projects, to take the data from the database to generate XML documents. Here's a note about the process: XML file: 1. ? xml version=1.0 Encoding=utf-8? 2 .... .

  • 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.