Java 元素类型“META”必须以匹配的结束标签“</META>”结尾

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16526248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:19:10  来源:igfitidea点击:

The element type "META" must be terminated by the matching end-tag "</META>"

javaxmlgoogle-app-enginesaxparser

提问by danny11

I've got the following error sometimes when I'm try to parse a XML file with Java (within GAE server):

当我尝试使用 Java(在 GAE 服务器中)解析 XML 文件时,有时会出现以下错误:

Parse: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 3; The element type "META" must be terminated by the matching end-tag "</META>".

Yet it is not happening all the time, sometimes It's works alright. The program parsing xml files and I've no problem with them.

然而它并不是一直发生,有时它工作正常。程序解析 xml 文件,我对它们没有问题。

This is the XML file I'm trying to parse: http://www.fulhamchronicle.co.uk/london-chelsea-fc/rss.xml

这是我试图解析的 XML 文件:http: //www.fulhamchronicle.co.uk/london-chelsea-fc/rss.xml

Any help will be appreciated. Thanks.

任何帮助将不胜感激。谢谢。



Update:

更新:

Thanks for the answer. I changed my code to a different parser and the good news the file is now parsing correctly. The bad it now moved for another feed same problem, same line despite completely different feed and it worked perfectly before. Could anyone think of why it's happening?

谢谢你的回答。我将代码更改为不同的解析器,好消息是文件现在可以正确解析。糟糕的是,它现在为另一个提要相同的问题而移动,尽管提要完全不同,但它还是在同一行,并且以前运行良好。谁能想到为什么会这样?

回答by Stephen C

That looks like it is a live document; i.e. one that changes fairly frequently. There is also no sign of a <meta>tag in it.

这看起来像是一个实时文档;即一个变化相当频繁的。也没有<meta>标签的迹象。

I can think of two explanations for what is happening:

对于正在发生的事情,我可以想到两种解释:

  • Sometimes the document is being generated or created incorrectly.

  • Sometimes you are getting an HTML error page instead of the document you are expecting, and the XML parser can't cope with a <meta>tag in the HTML's <head>. That is because the <meta>tag in (valid) HTML does not need to have a matching / closing </meta>tag. (And for at least some versions of HTML, it is not allowed to have a closing tag.)

  • 有时,文档的生成或创建不正确。

  • 有时您会得到一个 HTML 错误页面而不是您期望的文档,并且 XML 解析器无法处理<meta>HTML 的<head>. 那是因为<meta>(有效)HTML 中的标记不需要具有匹配/结束</meta>标记。(至少对于某些版本的 HTML,不允许有结束标记。)

To track this down, you are going to have to capture the precise input that is causing the parse to fail.

为了追踪这一点,您必须捕获导致解析失败的精确输入。

回答by dev.brutus

It is not XML but HTML:

它不是 XML 而是 HTML:

<!DOCTYPE htmlPUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">

< !DOCTYPE htmlPUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">

The XML parser will not parse it.

XML 解析器不会解析它。

I see the file hasn't any content and it doesn't look like valid RSS file. May be any server-side error occurs.

我看到该文件没有任何内容,而且看起来不像有效的 RSS 文件。可能发生任何服务器端错误。

回答by iceblue

There are two solutions:

有两种解决方案:

  1. You can try <meta/>instead of <meta>.

  2. Add spring.thymeleaf.mode=LEGACYHTML5in your application.propertiesfile.

  1. 您可以尝试<meta/>代替<meta>.

  2. 添加spring.thymeleaf.mode=LEGACYHTML5到您的application.properties文件中。

and added this dependency in you pom.xmlor build.gradlefile.

并在您pom.xmlbuild.gradle文件中添加了此依赖项。

pom.xml:

pom.xml

<dependency>
     <groupId>net.sourceforge.nekohtml</groupId>
     <artifactId>nekohtml</artifactId>
     <version>1.9.21</version>
 </dependency>

gradle:

gradle

compile 'net.sourceforge.nekohtml:nekohtml:1.9.21'

回答by Rohan C Bandara

can you use this tag

你能用这个标签吗

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

回答by user12023297

just apply (/) after every line with meta

只需/在每行带有 meta 后应用 ( )

<meta name=" " content=" " />

when using ,

使用时,

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

and really it works

真的有效