Parsing an XML file with a DTD schema on a relative path

前端 未结 4 1625
陌清茗
陌清茗 2020-12-17 20:02

I have the following java code:


DocumentBuilder db=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc=db.parse(new File(\"/opt/myfile\         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-17 20:36

    I used the custom EntityResolver like the example above but it still searched the DTD file in another base directory. So I debuged it and then found out I need to change user.dir system property. So I added this line to my application initialization method and it works now.

    System.setProperty("user.dir")
    

提交回复
热议问题