更新:为什么当我使用 google chrome 时收到错误消息,而当我使用 Windows 资源管理器时,它会显示一切正常。
我使用谷歌浏览器来运行我的网络服务器。 我收到以下错误: 我不确定为什么会收到此错误,我的文件位于正确的区域。
此 XML 文件似乎没有任何关联的样式信息。文档树如下所示。
<?xml version="1.0"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>news-feed</servlet-name>
<servlet-class>publisher.web.NewsFeedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>news-feed</servlet-name>
<url-pattern>/news.rss</url-pattern>
</servlet-mapping>
</web-app>
这是我的文件结构
NewsFeedServlet.java
public class NewsFeedServlet extends HttpServlet
{
private Logger logger = Logger.getLogger(this.getClass());
@Override
public void init(ServletConfig config) throws ServletException
{
logger.debug("init()");
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
throw new ServletException(e);
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("My Local News Feed");
feed.setLink("http://localhost:8080/publisher/");
feed.setDescription("This feed was created using ROME.");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try
{
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost/publisher", "publisher",
"publisher");
Statement statement = connection.createStatement();
ResultSet resultSet = statement
.executeQuery("select * from news_item;");
while (resultSet.next())
{
String title = resultSet.getString("title");
String url = resultSet.getString("url");
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(title);
entry.setLink(url);
entries.add(entry);
}
connection.close();
}
catch (SQLException e)
{
throw new ServletException(e);
}
resp.setContentType("text/xml");
feed.setEntries(entries);
Writer writer = resp.getWriter();
SyndFeedOutput output = new SyndFeedOutput();
try
{
//Send response to output stream
output.output(feed, writer);
}
catch (FeedException e)
{
logger.error("", e);
}
}
发布者日志:
2015-05-02 15:35:45,550 [http-nio-8080-exec-1] DEBUG publisher.web.NewsFeedServlet - init()
2015-05-02 15:41:08,137 [http-nio-8080-exec-4] DEBUG publisher.web.NewsFeedServlet - init()
最佳答案
那么无论如何,什么是“样式信息”以及格式良好的 XML 看起来如何?
“样式信息”实际上是一种转换,XML 到 HTML 的转换示例可以在 SELFHTML 上找到...
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- test.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html><head></head><body>
<xsl:for-each select="text">
<p align="center" style="font-family:Tahoma; font-size:48pt; color:red">
<xsl:value-of select="." />
</p>
</xsl:for-each>
</body></html>
</xsl:template>
</xsl:stylesheet>
现在 XML 只需要包含它...
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!-- test.xml -->
<root>
<text>Hello World</text>
<text>XML to HTML</text>
<text>Transformation</text>
<text>Client-Side</text>
<text>Depends On</text>
<text>Webbrowser</text>
</root>
...并将两个文件放在同一个地方不会产生“错误:此 XML 文件似乎没有任何与之关联的样式信息”消息。
关于xml - 错误 : This XML file does not appear to have any style information associated with it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30006832/