【发布时间】:2018-10-31 12:43:48
【问题描述】:
我正在尝试在 xml 文件中使用 HTML 标签,该文件稍后在视图中用于显示内容。我的问题,HTML 标记作为纯字符串传递,尽管我适当地转义了所有必要的字符。
<?xml version='1.0'?>
<selfassessment>
<topic>
<description>Die <strong> Zweckbestimmung </strong> ist ein eleme
Konsequenzen.</description>
<shortdesc>Zweckbestimmung</shortdesc>
<question>
<questiontext>Ihre fest:</questiontext>
<answer correct="false">Sie habenmung.</answer>
<answer correct="true"> erreichen sollen.</answer>
<answer correct="true">Das phyiert.</answer>
<answer correct="true">Die Chlektuellen eiten.</answer>
<answer correct="true">Die Beler "Workload".</answer>
<answer correct="true">Date.</answer>
<comment>All <br/><a href="/someLink" class="button">Erfahren Sie hier mehr</a></comment>
</question>
</topic>
</selfassessment>
显示的时候不实现html标签,直接粘贴到纯字符串中。
我已经看到这里提出的所有相关问题,我尝试使用 CDATA,但没有成功。我在这里缺少什么吗?它应该像这样工作,不是吗?
提前致谢。
编辑:(涉及php代码)
获取xml文件:
function getXmlFile(){
$xml = null;
$xmlFile = '/var/www/html/typo3conf/ext/extKeyHere/Resources/Private/XML/data.xml';
if (file_exists($xmlFile)) {
$xml = simplexml_load_file($xmlFile);
} else {
exit("Datei $xmlFile kann nicht geöffnet werden.");
//echo "Datei $xmlFile kann nicht geöffnet werden.";
}
return $xml;
}
后来我像这样使用它:
function __construct($xmldata) {
$this->xml = $xmldata;
$this->calculateResults();
}
private function calculateResults() {
$page = 0;
//iterating over xml file
foreach ($this->xml->topic as $thema) {
$this->topics[$page] = $thema->description;
and so on.....
//passing it to the view
$this->view->assignMultiple(array(
'allQuestions' => $allQuestions,
'questions' => $questions,
....
视图内的代码:
<form method='post' action="{url}">
<h3>{allQuestions.themaDescr}</h3>
<f:for each="{allQuestions.thema.question}" as="question" iteration="i">
<div class='question'><p><strong>Frage {i.cycle}</strong>:
{question.questiontext}</p>
<f:for each="{question.answer}" as="answer" iteration="ii">
<div class='answer'><input type='checkbox' name='A{page}
{i.cycle}{ii.cycle}'/>
<div class='subanswer' for='A{page}{i.cycle}{ii.cycle}'>
{answer}
</div>
</div>
</f:for>
</div>
</f:for>
<input type='hidden' name='page' value='{allQuestions.page}'/>
<f:if condition="{allQuestions.nextThema}">
<f:then>
<button type='submit'>Ergebnisse anzeigen</button>
</f:then>
<f:else>`
<button type='submit'>Nächste Seite</button>
</f:else>
</f:if>
</form>
没有错误,除了我提到的 html 标签显示为纯文本外,一切正常。 顺便说一句,这是 Typo3,但我认为这并不重要,除了我如何将数据传递给视图并显示它。
【问题讨论】:
-
我在该代码中没有看到任何
CDATA -
您可以从 URL 获取示例:stackoverflow.com/questions/4412395/…
-
@kerbholz 也许我不够清楚。我也尝试过使用 CDATA,但它没有用。但我认为在转义 html 标记字符后它应该仍然可以工作。
-
@Vish 我已经阅读了这个问题,但它对我不起作用。对于 CDATA 部分,HTML 标记也无法识别,最终也以纯字符串形式结束,或者被完全忽略
-
如何从 XML 中提取 HTML 并显示它?这是关键部分。