我在JSP页面中生成XML,我在其中使用CDATA部分。问题是单个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部分被转换为多个部分。我不希望这种情况发生。
答案 0 :(得分:1)
我的坏。这只是chrome显示XML的方式。我查看源代码并使用firefox和fount打开页面,它只是预期的1个CDATA部分。