1

Is there anyway to 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.

2
  • I had a look at the both APIs. It says org.apache.html.dom.HTMLDocumentImpl implements org.w3c.dom.Document. Commented Aug 18, 2010 at 23:53
  • I'm already aware of this. Is there any way to convert Document to HTMLDocumentImpl? Commented Aug 19, 2010 at 0:28

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.