将 org.w3c.dom.Document 转换为 org.apache.html.dom.HTMLDocumentImpl
无论如何,是否可以将 org.w3c.dom.Document 的实例转换为 org.apache.html.dom.HTMLDocumentImpl。
我需要解析文档中的图像,并且 HTMLDocumentImpl 有一个提取图像的方法。
我尝试了多种方法,例如类型转换和 importNode,但它不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然您说您尝试过强制转换,那么我假设您拥有的
Document
实例不是org.apache.html.dom.HTMLDocumentImpl
。有两件事可能值得一试:1) getImages() 方法实际上是在接口 org.w3c.dom.html.HTMLDocument 上定义的,它更重要可能由您拥有的任何类型的 Dom 文档来实现。因此,您应该能够执行以下操作:
2) 如果这不起作用,则
getImages()
方法实际上不会做任何比以下更奇特的事情:Since you said you tried casting, I'll assume that the
Document
instance you have is not aorg.apache.html.dom.HTMLDocumentImpl
. Two things that might be worth a shot:1) The
getImages()
method is in fact defined on the interfaceorg.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:2) If that doesn't work, the
getImages()
method is really not going to do anything much fancier than: