【问题标题】:XML to string in velocityXML 到字符串的速度
【发布时间】:2011-09-29 22:36:39
【问题描述】:

我的 XML 文件包含带有格式化 HTML 的节点。 我正在尝试将 html 内容打印到页面,但速度正在剥离 HTML 标签。

如何使用速度打印存储在 XML 文件中的 html 内容?

XML 文件

<?xml version="1.0" encoding="utf-8"?>
<system-data-structure>
  <heading>This is a Title</heading>
  <main>
    <content>
      <h1>this is formatted html</h1>
      <p>content I want <b>to</b> <em>show</em> on my page
    </p>
    </content>
  </main>
</system-data-structure>

速度代码

#set ($html = $contentRoot.getChild('main').getChild('content'))
<h1>$contentRoot.getChild('heading').value</h1>
<div>$html.value</div>

注意:这是我第一次使用速度引擎

【问题讨论】:

    标签: html xml apache templates velocity


    【解决方案1】:

    速度不会剥离任何东西。如果您配置了正确的事件处理程序,您可以拥有 Velocity escape html 输出(我认为您不想要)。但是 Velocity 不支持剥离任何内容。

    你实际上得到了什么输出?您是否正在使用为您配置 Velocity 的框架或 CMS?也许是其他东西“剥离了 html 标签”。

    【讨论】:

    • 我在 Cascade Server CMS 中使用速度来格式化模板,它将 XML 数据解析为一个对象 ($contentRoot)。事实证明,有一个 $_SerializerTool 对象可以将 XML 对象解析回字符串。 hannonhill.com/kb/Script-Formats/#serializer-tool
    猜你喜欢
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 2022-08-19
    • 2011-04-28
    • 2020-12-09
    相关资源
    最近更新 更多