2010-08-18 45 views
1

有沒有辦法將org.w3c.dom.Document的實例轉換爲org.apache.html.dom.HTMLDocumentImpl。將org.w3c.dom.Document轉換爲org.apache.html.dom.HTMLDocumentImpl

我需要解析Document中的圖像,並且HTMLDocumentImpl有一個提取圖像的方法。

我試過幾種方法,如類型轉換和importNode,但它不起作用。

+0

我有一個看看這兩個API。它說org.apache.html.dom.HTMLDocumentImpl實現了org.w3c.dom.Document。 – sarahTheButterFly 2010-08-18 23:53:53

+0

我已經意識到這一點。有什麼辦法將Document轉換爲HTMLDocumentImpl? – migscabral 2010-08-19 00:28:26

回答

1

既然你說你嘗試了鑄造,我會假設你的Document實例不是org.apache.html.dom.HTMLDocumentImpl。有兩件事值得一試:

1)getImages()方法實際上是在界面org.w3c.dom.html.HTMLDocument上定義的,它更可能由您擁有的任何類型的Dom文檔實現。因此,你應該能夠做這樣的事情:

if (doc instanceof HTMLDocument) { 
    images = ((HTMLDocument) doc).getImages(); 
} 

2)如果不工作,getImages()方法真的不打算做任何事情遠遠愛好者:

images = doc.getElementsByTagName("img"); 
相關問題