【问题标题】:ERROR: This XML file does not appear to have any style information associated with it错误:此 XML 文件似乎没有任何关联的样式信息
【发布时间】:2015-05-02 19:58:51
【问题描述】:

更新:为什么当我使用谷歌浏览器时我收到错误消息,而当我使用 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()

【问题讨论】:

  • 嗨,你能告诉我们你尝试的代码吗?
  • @Juxhin 我添加了代码
  • 太好了,对任何试图回答这个问题的人的最后一个请求。请明确总结您希望实现的目标,并尽可能添加任何堆栈跟踪。
  • @Juxhin 我添加了发布者日志,我只想打印我的 servlet 程序中的项目

标签: xml apache google-chrome tomcat rss


【解决方案1】:

“此 XML 文件似乎没有任何关联的样式信息。”在大多数情况下,它本身不是问题。它只是说明响应缺少样式表,因此浏览器只显示原始 XML。

如果你在调试某些东西时遇到了这个页面,真正的问题通常与这个警告无关。检查 XML 中写的内容并在 google 上搜索,没有“此 XML 文件不出现~”一词可能会解决您的问题。

【讨论】:

    【解决方案2】:

    Chrome 没有实现 rss 阅读器。您需要安装扩展程序。有好几个。

    【讨论】:

      【解决方案3】:

      那么无论如何,什么是“样式信息”以及格式良好的 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 文件似乎没有任何与之关联的样式信息”消息。

      印象

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-28
        • 1970-01-01
        • 1970-01-01
        • 2017-11-04
        • 2012-07-08
        • 1970-01-01
        • 2013-01-26
        相关资源
        最近更新 更多