2010-05-16 56 views
0

創建XML文檔如果我試圖通過這個代碼來創建一個Java applet的一個新的XML文檔:在Java小程序

http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#newInstance()

DocumentBuilderFactory.newInstance(); 

我會得到這個錯誤:

Java Plug-in 1.6.0_19 
Using JRE version 1.6.0_19-b04 Java HotSpot(TM) Client VM 

javax.xml.parsers.FactoryConfigurationError: Provider <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> not found 
     at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source) 

我不在乎DTD的。

  1. 它爲什麼要找它?
  2. 我該怎麼樣在java applets中創建一個xml文檔
  3. 我該如何讓它工作?

封閉的html文件看起來是這樣的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<title>Loading...</title> 
</head> 

Can some comment this thread

The problem was with the entity resolver, which points to the w3c.org web site. The access to the reference DTDs on this site has been restricted for application use. The solution was to implement my own entity resolver.

相關:

  1. http://forums.sun.com/thread.jspa?threadID=515055
  2. org.apache.xerces.jaxp.SAXParserFactoryImpl not found when importing Gears API in GWT
  3. http://java.itags.org/java-desktop/4839/

回答

1

如果你正在做的是呼籲DocumentBuilderFactory.newInstance();那麼這應該不會導致錯誤。您鏈接到的帖子不相關。

javax.xml.parsers.FactoryConfigurationError: Provider <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> not found

這表明一些奇怪的配置錯誤/缺陷。提供者應該(我認爲)是JAXP實現的工廠類名稱。檢查你是不是在做一些奇怪的事情,比如設置javax.xml.parsers.DocumentBuilderFactory系統屬性或者在你的Applet類路徑上有一個無效的META-INF/services/javax.xml.parsers.DocumentBuilderFactory文件。