2015-04-04 105 views
2

我有xml文件的這樣的報頭:文檔類型聲明爲根元素類型「的plist」必須以結束「>」

<?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文件!

如何解決這個問題?

回答

1

DOCTYPE不是一個元素,最後沒有固體。所以刪除/之前的>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"/> 
Here ------------------------------------------------------------------------------------------------^ 
相關問題