我有这样的xml文件头:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"/>
<plist version="1.0">
<dict>
<key>frames</key>
</dict>
</plist>
我想用org.w3c.dom.Document
来阅读它。当我在这段代码中解析它时
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(path);
我得到以下例外:
[Fatal Error] atlas_ID117.plist:2:102: The document type declaration for root element type "plist" must end with '>'.
Exception in thread "main" java.lang.NullPointerException
at main.PlistReader.findFramesList(PlistReader.java:36)
at main.PlistReader.<init>(PlistReader.java:32)
at main.Main.main(Main.java:12)
结果builder.parse
方法返回null。但我无法更改xml文件!
如何解决这个问题?
答案 0 :(得分:1)
DOCTYPE
不是元素,并且最后没有固定。因此,请移除/
之前的>
:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"/>
Here ------------------------------------------------------------------------------------------------^