0
幾周前,我在此處發佈了issue。現在我遇到了另一種情況的類似問題。我創建了一個java上傳,我想檢查一個XML文件是否格式正確。檢查後,我想刪除它。但如果轉換失敗,我不能刪除該文件。 我創建了一個更簡單的例子,在我的本地計算機上運行它,我遇到了同樣的問題。請參閱下面的我的源代碼。您可以輕鬆地複製並粘貼它並自行嘗試。Saxon XML驗證:驗證失敗時無法刪除XML文件
我發現了一個錯誤,可能是我幾周前報告的錯誤,或者我錯過了代碼中的某些東西?我使用了Saxon 9.4HE。
public class TestClass
{
public static void main (String[] args) throws Exception
{
boolean isWellFormed = isXMLwellformed(new File("work/file.xml"));
if(isWellFormed) System.out.println("File is well formed");
else
{
System.out.println("File is not well formed");
}
FileUtils.deleteDirectory(new File("work"));
}
private static boolean isXMLwellformed(File file)
{
boolean isWellformed = true;
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource source = new StreamSource(file);
try
{
Transformer trans = factory.newTransformer();
SAXResult sink = new SAXResult(new DefaultHandler());
trans.transform(source, sink);
}
catch (TransformerException err)
{
System.err.println("Validation failed: " + err.getMessage());
isWellformed = false;
}
return isWellformed;
}
}
請問我們是否在Saxon 9.5中問題仍然存在? –