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);
相关文档:
如果你曾经用过Perl或任何其他内建正则表达式支持的语言,你一定知道用正则表达式处理文本和匹配模式是多么简单。如果你不熟悉这个术语,那么“正则表达式”(Regular Expression)就是一个字符构成的串,它定义了一个用来搜索匹配字符串的模式。
许多语言,包括Perl、PHP、Python、JavaScript和JScript,都支 ......
第1章 Java语言概述
1.1 知识概括
1.2 实验练习
1.2.1 一个简单的应用程序
class里不能再有class,无论有没有public修饰,class都是平行关系,在bin文件夹中会产生各自的字节码文件。同一个.java源文件中至多有一个public class,如果不想再一个源文件中写多个类,就各自写源程序,并把类公用,即用public修饰。
1.2.2 ......
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 ......
①继承TimerTask,重写run方法
package bamboo.task;
import java.util.TimerTask;
public class TimeTaskTest extends TimerTask{
@Override
public void run() {
System.out.println("hi");
}
}
②通过timer来设置某个时间来调用,或者是相隔多长时间调用
package bamboo.test;
......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
im ......