How to add CDATA tag when php generates xml_PHP tutorial

WBOY
Release: 2016-07-13 10:16:36
Original
1112 people have browsed it

How to add CDATA tags when php generates xml

This article describes how to add CDATA tags when php generates xml. Share it with everyone for your reference. The specific implementation method is as follows:

In fact, it is very simple to add the CDATA tag when PHP generates xml, because it is a tag that can store various contents in xml. Here is an example that I hope will be helpful to you.

Where there is code, there is truth. Paste the code. Don’t treat as a suffix or suffix. In fact, it can be a label.

The specific code is as follows:

The code is as follows:

$dom = new DOMDocument("1.0");
// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// create root element
$root = $dom->createElement("toppings");
$dom->appendChild($root);
// create child element
$item = $dom->createElement("item");
$root->appendChild($item);
// create text node
$text = $dom->createTextNode("pepperoni");
$item->appendChild($text);
// create attribute node
$price = $dom->createAttribute("price");
$item->appendChild($price);
// create attribute value node
$priceValue = $dom->createTextNode("4");
$price->appendChild($priceValue);
// create CDATA section
$cdata = $dom->createCDATASection(" Customer requests that pizza be sliced ​​into 16 square pieces ");
$root->appendChild($cdata);
// create PI
$pi = $dom->createProcessingInstruction("pizza", "bake()");
$root->appendChild($pi);
// save and display tree
echo $dom->saveXML();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/896778.htmlTechArticleHow to add CDATA tags when php generates xml. This article describes how to add CDATA tags when php generates xml. Share it with everyone for your reference. The specific implementation method is as follows: In fact, php generates...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!