XULRunner with Java: JavaXPCOM Tutorial 3
6 加载页面的W3C DOM访问
6.1 mozdom4java库
访问W3C DOM树比访问Mozilla的DOM树要好,因为它是一个动态访问HTML和XML的DOM树的标准。为了实现这个,我们使用从Mozilla
DOM到W3C DOM的java Bridge。有一个叫做mozdom4java的项目http://mozdom4java.mozdev.org/index.html。
下载这个包后,我们把jar包放到classpath里。例如,我们增加一个按钮来抽取HTML文档里的所有链接。
// When that button is pressed, then we obtain the HTML document corresponding to
// the URL loaded in browser. Next, we extract all its child nodes with 'a' tag name
// and print its content.
final ToolItem anchorItem = new ToolItem(toolbar, SWT.PUSH);
anchorItem.setImage(getImage("resources/anchors.png"));
anchorItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// First, we obtain a Mozilla DOM Document representation
nsIDOMDocument doc = browser.getDocument();
// Get all anchors from the loaded HTML document
nsIDOMNodeList nodeList = doc.getElementsByTagName("a");
for ( int i = 0; i < nodeList.getLength(); i++ ){
// Get Mozilla DOM node
nsIDOMNode mozNode = nodeList.item(i);
// Get the appropiate interface
nsIDOMHTMLAnchorElement mozAnchor =
(nsIDOMHTMLAnchorElement) mozNode.queryInterface(
nsIDOMHTMLAnchorElement.NS_IDOMHTMLANCHORELEMENT_IID);
// Get the corresponding W3C DOM node
HTMLAnchorElement a = (HTMLAnchorElement)
HTMLAnchorElementImpl.getDOMInstance(mozAnchor);
相关文档:
JAVA容器
解释一:
容器(Container)
Spring 提供容器功能,容器可以管理对象的生命周期、对象与对象之间的依赖关系,您可以使用一个配置文件(通常是XML),在上面定义好对象的名称、如何产生(Prototype 方式或Singleton 方式)、哪个对象产生之后必须设定成为某个对象的属性等,在启动容器之后,所有 ......
BODY { color: #000000; font-size: 9pt; font-family: 宋体 }
TABLE { font-size: 9pt; font-family: 宋体 }
SimpleDateFormat sdfy = new SimpleDateFormat("HH:mm");
String tt =
"Tue Feb 09 10:43:00 CST 2010";
&n ......
今天碰到了一个很变态的问题,写了一个很简单的HelloWord.java,内容如下:
package com.yanjiuyanjiu;
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
在eclips ......
LADyR是西班牙一个实验室有个web extraction的项目 http://ladyr.es/index.php?id=75 当然这个项目还没出来,不过里面有个介
绍用java嵌入浏览器的教程(http://ladyr.es/wiki/wiki/XPCOMGuide)很不错。所以把这篇文章翻译一下,顺便说说自己学习这篇
文章值得注意的地方。说明一下我使用的操作系统是windows xp。下面都 ......