【问题标题】:JSP Multiple CDATA Sections when I need 1当我需要 1 时 JSP 多个 CDATA 部分
【发布时间】:2016-08-04 02:06:26
【问题描述】:

我正在使用 CDATA 部分的 JSP 页面内生成 XML。问题是单个 CDATA 部分被转换为多个 CDATA。这是我的代码:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><?xml   version="1.0" encoding="UTF-8"?>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/xml;charset=UTF-8" language="java" %>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/">

  <channel>
        <title>My Website</title>
        <link>http://www.mywebsite.zz/</link>
        <description>
            Sample description
        </description>
        <language>en-us</language>
        <item>
                <title>${item.title}</title>
                <link>${storyLink}</link>
                <guid isPermaLink="true">${storyLink}</guid>
                <pubDate><fmt:formatDate type="both"
                        timeZone="UTC"
                        pattern="yyyy-MM-dd'T'HH:mm:ssz"
                        dateStyle="short" timeStyle="short"
                        value="${item.createdTime}" />
                </pubDate>
                <description>
                    ${item.description}
                </description>
                <content:encoded>
                    <![CDATA[
                       <!doctype html>
                          <html lang="en" prefix="op: http://media.facebook.com/op#">
                          <head>
                              <meta charset="utf-8">
                              <link rel="canonical" href="${storyLink}">
                              <meta property="op:markup_version" content="v1.0">
                       <body>
                              <article>
                                <header>
                                    <h1>${item.title}</h1>
                                </header>
                                ${item.post}
                              </article>
                       </body>
                   ]]>
                </content:encoded>

            </item>
    </channel>
</rss>

这是我得到的回复:

<rss xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
  <title>Carbonated</title>
  <link>http://www.mywebsite.zz/</link>
  <description>Sample description</description>
  <language>en-us</language>
    <item>
      <title>
        My Title
      </title>
      <link>
        http://localhost/mypost
      </link>
      <guid isPermaLink="true">
        http://localhost/mypost
      </guid>
      <pubDate>2016-04-06T10:51:48UTC</pubDate>
      <description>
        This is a description
      </description>
      <content:encoded>
        <![CDATA[
          <!doctype html>
          <html lang="en" prefix="op: http://media.facebook.com/op#">
          <head>
            <meta charset="utf-8">
            <link rel="canonical" href="ht
        ]]>
        <![CDATA[
            tp://localhost/mypost">
            <meta property="op:markup_version" content="v1.0">
          </head>
        <body>
          <article>
            <header>
              <h1>Heading</h1>
            </header>
            <p>topic post</p>
          </article>
        </body>
      ]]>
    </content:encoded>
  </item>

看到单个 CDATA 节被转换为多个节。我不希望这种情况发生。

【问题讨论】:

    标签: java xml jsp


    【解决方案1】:

    我的坏。这只是 chrome 显示 XML 的方式。我查看源代码并使用 firefox 打开页面,发现它只有 1 个 CDATA 部分,正如预期的那样。

    【讨论】:

      猜你喜欢
      • 2010-09-09
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 2023-01-22
      • 1970-01-01
      相关资源
      最近更新 更多