首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:此XML文件似乎没有任何与之关联的样式信息

错误:此XML文件似乎没有任何与之关联的样式信息
EN

Stack Overflow用户
提问于 2015-05-03 03:58:52
回答 3查看 33.4K关注 0票数 4

更新:为什么当我使用google chrome时,我会收到错误信息,而当我使用Windows资源管理器时,它会显示一切正常。

我使用google chrome来运行我的web服务器。我得到以下错误:我不确定为什么我得到这个错误,我有文件在正确的区域。

此XML文件似乎没有任何与其关联的样式信息。文档树如下所示。

代码语言:javascript
运行
复制
<?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

代码语言:javascript
运行
复制
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);
        }
    }

发布者日志:

代码语言:javascript
运行
复制
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()
EN

回答 3

Stack Overflow用户

发布于 2019-07-13 16:07:08

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

如果您正在调试某些东西并遇到此页,则真正的问题通常与此警告无关。检查一下XML中写了什么,然后谷歌一下,去掉“这个XML文件没有出现~”这个词就可以解决你的问题了。

票数 1
EN

Stack Overflow用户

发布于 2015-11-06 01:56:46

Chrome没有实现rss阅读器。您需要安装扩展。现在已经有好几个了。

票数 0
EN

Stack Overflow用户

发布于 2022-02-17 15:09:24

那么,什么是“样式信息”,格式良好的XML看起来如何呢?

“样式信息”实际上是一种转换,XML到HTML的转换示例可以在SELFHTML上找到...

代码语言:javascript
运行
复制
<?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只需要包含它...

代码语言:javascript
运行
复制
<?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>

...and将这两个文件放在同一位置不会产生"ERROR: This XML file it not any style information with it“消息。

印象

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30006832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档