Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

This is the XML file I'm trying to parse: 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?

like image 802
danny11 Avatar asked May 13 '13 15:05

danny11


2 Answers

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.

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.)

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

like image 175
Stephen C Avatar answered Oct 24 '22 01:10

Stephen C


There are two solutions:

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

  2. Add spring.thymeleaf.mode=LEGACYHTML5 in your application.properties file.

and added this dependency in you pom.xml or build.gradle file.

pom.xml:

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

gradle:

compile 'net.sourceforge.nekohtml:nekohtml:1.9.21'
like image 4
iceqing Avatar answered Oct 24 '22 03:10

iceqing