小编Mih*_*vak的帖子

将CDATA添加到xml节点

这个PHP代码工作正常,但如何将CDATA添加到内容节点?

 <?php
 $xml = new DomDocument("1.0", "UTF-8");
 $xml->load('xmldata.xml');

 $title    = $_POST['title'];
 $avtor    = $_POST['avtor'];
 $date     = $_POST['date'];
 $category = $_POST['category'];
 $content  = $_POST['content'];

$rootTag = $xml->getElementsByTagName("root")->item(0);

   $postingTag = $xml->createElement("posting");

     $titleTag    = $xml->createElement("title",    $title);
     $avtorTag    = $xml->createElement("avtor",    $avtor);
     $dateTag     = $xml->createElement("date",     $date);
     $categoryTag = $xml->createElement("category", $category);
     $contentTag  = $xml->createElement("content",  $content);

     $postingTag->appendChild($titleTag);
     $postingTag->appendChild($avtorTag);
     $postingTag->appendChild($dateTag);
     $postingTag->appendChild($categoryTag);
     $postingTag->appendChild($contentTag);

   $rootTag->appendChild($postingTag);

$xml->formatOutput = true;
$xml->save('xmldata.xml');
Run Code Online (Sandbox Code Playgroud)

php xml

4
推荐指数
1
解决办法
7719
查看次数

标签 统计

php ×1

xml ×1