相关疑难解决方法(0)

使DocumentBuilder.parse忽略DTD引用

当我在这个方法中解析我的xml文件(变量f)时,我收到一个错误

C:\ Documents and Settings\joe\Desktop\aicpcudev\OnlineModule\map.dtd(系统找不到指定的路径)

我知道我没有dtd,也不需要它.如何在忽略DTD引用错误的同时将此File对象解析为Document对象?

private static Document getDoc(File f, String docId) throws Exception{
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(f);


    return doc;
}
Run Code Online (Sandbox Code Playgroud)

java dtd document

77
推荐指数
4
解决办法
7万
查看次数

离线时无法解析hibernate.cfg.xml

每当我与互联网断开连接时,我都会遇到以下异常:

org.hibernate.HibernateException: Could not parse configuration: com/mashlife/resources/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)

Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
    ... 45 more
Run Code Online (Sandbox Code Playgroud)

只有当我离线发生.在解析配置时,hibernate是否尝试读取DTD?这里的根本原因是什么?

这是我的hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/foo</property>
        <property name="connection.username">user</property>
        <property name="connection.password">pass</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

        <!-- Disable the …
Run Code Online (Sandbox Code Playgroud)

java hibernate

19
推荐指数
3
解决办法
4万
查看次数

标签 统计

java ×2

document ×1

dtd ×1

hibernate ×1