这是我的示例XML
<?xml version="1.0" standalone="no"?>
<!DOCTYPE factory-requirements SYSTEM "factory.7.0.dtd">
<data name="product">
<product name="container">
<one>20 feet</one>
<two>50 feet</two>
</product>
</data>
当我尝试将此文件传递到我的文档时,我收到错误。
java.io.FileNotFoundException: C:\Documents and Settings\johnB\workspace\project\factory.7.0.dtd (The system cannot find the file specified)
似乎它正在寻找我没有的DTD。我只需要将此文件解析为XML并获取产品。我不会针对DTD验证此XML,因为我没有DTD,我们只从供应商处获取此XML。
这是我的代码:
File fstream = new File("C:/Documents and Settings/johnB/workspace/project/factory_product.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fstream);
doc.getDocumentElement().normalize();
我可以做什么,因此在解析时会忽略<!DOCTYPE factory-requirements SYSTEM "factory.7.0.dtd">
?