<?xml version="1.0" encoding="utf-8"?>
<Template/>
<tmp_name>hello</tmp_name>
<tmp_subject>Launch Business</tmp_subject>
<EContent><![CDATA[<p>xdfgdfgdfgdf</p>]]></EContent>
<PDFContent><![CDATA[<p>gdfgdfgdfgdfg</p>`enter code here`]]></PDFContent>
为什么我缺少关闭根标记?一切都应该很好,只有我错过的关闭根标签...这是我的代码
$name=$_POST['tmp_name'];
$xml = new DOMDocument('1.0','utf-8');
$xml->formatOutput = true;
$root = $xml->createElement('Template');
$root = $xml->appendChild($root);
$title = $xml->createElement('tmp_name');
$title = $xml->appendChild($title);
$text = $xml->createTextNode($name);
$text = $title->appendChild($text);
$title1 = $xml->createElement('tmp_subject');
$title1 = $xml->appendChild($title1);
$text1 = $xml->createTextNode($_POST['tmp_subject']);
$text1 = $title1->appendChild($text1);
$title2 = $xml->createElement('EContent');
$title2 = $xml->appendChild($title2);
$text2 = $xml->createCDATASection($_POST['EContent']);
$text2 = $title2->appendChild($text2);
$title3 = $xml->createElement('PDFContent');
$title3 = $xml->appendChild($title3);
$text3 = $xml->createCDATASection($_POST['PDFContent']);
$text3 = $title3->appendChild($text3);
$xml->save($curr_path.'../../../templates/'.$_POST['tmp_name'].'.xml');
答案 0 :(得分:-1)
您正在将标题等标签附加到文档中。您应该将它们附加到$root
节点。所以,而不是;
$title = $xml->appendChild($title);
你的代码应该是;
$title = $root->appendChild($title);