Table of Contents
How to add CDATA tag when php generates xml, phpxmlcdata tag
How to extract the content of CDATA in xml with php?
Who has used Xstream and used it to generate xml with cdata tags to parse xml with cdata tags
Home Backend Development PHP Tutorial How to add CDATA tag when php generates xml, phpxmlcdata tag_PHP tutorial

How to add CDATA tag when php generates xml, phpxmlcdata tag_PHP tutorial

Jul 13, 2016 am 10:17 AM
php xml Label

How to add CDATA tag when php generates xml, phpxmlcdata tag

The example in 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 think of <![CDATA[ $text]]> as a suffix or suffix. In fact, it can be a label.

The specific code is as follows:

Copy code The code is as follows:
<?php
$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();
?>

I hope this article will be helpful to everyone’s PHP programming design.

How to extract the content of CDATA in xml with php?

You can try to use simpleXml to parse this file, which is much simpler than EXpat.

Who has used Xstream and used it to generate xml with cdata tags to parse xml with cdata tags

CDATA represents in the XML specification that its internal data should not be escaped, that is, characters such as <, > will not be interpreted.
When parsing such xml, the interpreter will read its content as it is without any special processing.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/895111.htmlTechArticleHow to add CDATA tag when php generates xml, phpxmlcdata tag This article describes how to add CDATA tag when php generates xml. method. Share it with everyone for your reference. The specific implementation method is as follows...
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles