无效的 XML:第 6 行的错误:元素类型"hr"必须由匹配的结束标记终止"</hr>"



当我使用rome解析xml链接时:

package com.dolphin.soa.post;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.ParsingFeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
import lombok.extern.slf4j.Slf4j;
import java.net.ConnectException;
import java.net.URL;
/**
* @author dolphin
*/
@Slf4j
public class MiniExample {
public static void main(String[] args) {
try {
SyndFeed feed = new SyndFeedInput().build(new XmlReader(new URL("http://yechengfu.com/feed.xml")));
} catch (ConnectException connectException) {
log.error("rss parse error", connectException);
} catch (ParsingFeedException e){
log.error("rss parse error", e);
}catch (Exception e) {
log.error("rss parse error", e);
}
}
}

显示错误Invalid XML: Error on line 6: The element type "hr" must be terminated by the matching end-tag "</hr>".我检查了xml链接,没有发现任何非标准格式。为什么会发生这种情况?有可能解决吗?这是我的依赖项:

api "com.rometools:rome:1.15.0"

调用"http://yechengfu.com/feed.xml"是一个小的html文件(带有一个<hr>标签(:

<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx/1.19.2</center>
</body>
</html>

如果运行curl:这样的命令,您可以看到这一点

curl http://yechengfu.com/feed.xml

页面在普通浏览器中重定向,但curl和XmlReader不会自动遵循重定向。如果你给卷曲"-L";参数,它将跟随到feed.xml文件。

我想你将不得不阅读如何配置nginx,并将其用作反向代理,而不是重写URL。

最新更新