2013-10-10 61 views
1

我需要使用Simple XML將數據插入紅色<title> DATA HERE </title>和此 <description> <text> DATA HERE</text> </description> 的塊中。下面是XML樹形 enter image description here將XML數據插入選定標記

下面是我的PHP代碼從創建從<question> XML標籤和數據以後的樣品,不過我不知道該怎麼做上面。

$questionLoad = $xml->children()[0]->addChild('question'); 
$textQue = $questionLoad->addChild('text', $que); 
$optionNode = $questionLoad->addChild('option'); 
$ans1 = $optionNode->addChild('text', $answer1); 
$score = $optionNode->addChild('score', $score1); 
$explain = $optionNode->addChild('explanation'); 
$expl1 = $explain->addChild('text', $explanation1); 

$xml->asXML('test.xml'); 

回答

0

像這樣:

http://3v4l.org/8F5eQ

<?php 
$xml = '<?xml version="1.0" encoding="UTF-8"?> 
<quizzes> 
    <quiz> 
     <title> 
     </title> 
     <description> 
      <text> 
      </text> 
     </description> 
    </quiz> 
</quizzes>'; 

$quizzes = new SimpleXMLElement($xml); 

$quizzes->quiz[0]->title = "TITLE"; 
$quizzes->quiz[0]->description->text = "DESCRIPTION"; 

echo $quizzes->asXML(); 
?> 

輸出:

<?xml version="1.0" encoding="UTF-8"?> 
<quizzes> 
    <quiz> 
     <title>TITLE</title> 
     <description> 
      <text>DESCRIPTION</text> 
     </description> 
    </quiz> 
</quizzes> 
+0

它不是做什麼,我需要,但它幫助我設計一個新的解決方案,謝謝非常。 – mrAfzaL