I need to insert data in the block of red <title> DATA HERE </title>
and in this <description> <text> DATA HERE</text> </description>
using Simple XML. Below is a sample of the XML tree-
Below is my PHP code from creating the XML tags and data from <question>
onward but I have no clue how to do the above.
$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');
Like this:
<?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();
?>
Outputs:
<?xml version="1.0" encoding="UTF-8"?>
<quizzes>
<quiz>
<title>TITLE</title>
<description>
<text>DESCRIPTION</text>
</description>
</quiz>
</quizzes>