Converting org.w3c.dom.Document to org.apache.html.dom.HTMLDocumentImpl
Is there anyway to 开发者_StackOverflow中文版convert an instance of org.w3c.dom.Document to org.apache.html.dom.HTMLDocumentImpl.
I need to parse the images inside the Document and HTMLDocumentImpl has a method for extracting the images.
I've tried several methods like typecasting, and importNode but it doesn't work.
Since you said you tried casting, I'll assume that the Document
instance you have is not a org.apache.html.dom.HTMLDocumentImpl
. Two things that might be worth a shot:
1) The getImages()
method is in fact defined on the interface org.w3c.dom.html.HTMLDocument
, which is more likely to be implemented by whatever type of Dom document you have. Thus, you should be able to do something like:
if (doc instanceof HTMLDocument) {
images = ((HTMLDocument) doc).getImages();
}
2) If that doesn't work, the getImages()
method is really not going to do anything much fancier than:
images = doc.getElementsByTagName("img");
精彩评论