hibernate - document builder add html tags to doc
问题描述
This is actually related to Hibernate when it tries to load the persistence.xml
locally.
Here is the stacktrace and error
ERROR javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1.a: Cannot find the declaration of element 'HTML'.
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
Actually the persistence xml is plain (I minimized it from the larger one as it makes no difference)
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
</persistence>
The issue is this line in the documentbuilder
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(resolver);
doc = docBuilder.parse(source);
>The doc after parsed has HTML tags in it which it should not because its just a xml. I traveresed the nodes in the doc and got below elements
Found element HTML
Found element HEAD
Found element BODY
Found element PERSISTENCE
This is why XSD schema validation fails as it was not expecting html elements.
Anyone knows why and how to get over this.
解决方案
发现问题。我在类路径中有 nekohtml-1.9.22.jar。它是一个解析器,也是一个标签平衡器。它被用作默认解析器,因为它没有在 xml 中找到 HTML 标签,所以添加了它。奇怪的是它不应该是 XML 的默认值。无论如何从类路径中删除它解决了这个问题。
推荐阅读
- sql - Redshift Avg 不返回小数
- postgresql - 'Yarn Prisma Migrate Dev' 失败并出现错误:P1000 说明提供的凭据无效。这些凭据适用于所有其他机器
- awk - awk:利用一个文件中的值在另一个文件中搜索
- r - 使用环境变量使用 tidyverse 重命名列
- google-sheets - 在 Google 表格中,如何输出/引用一个月内最后一个底部单元格的值
- ios - 无法获取注册令牌
- swift - 为所有视图设置一次背景颜色 | SwiftUI
- python - Jupyter Notebook TOC 未显示
- c# - 如何让我的不和谐机器人显示来自我的服务器的用户名?C#
- r - 打印由 dplyr R 中的自定义函数生成的中间输出