?? myhandler.java
字號:
package com.j2medev.chapter10;
import javax.microedition.lcdui.Form;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class MyHandler extends DefaultHandler{
private Form form = null;
public MyHandler(Form _form) {
form = _form;
form.deleteAll();
}
public void startDocument() throws SAXException {
}
public void characters(char[] ch, int start, int length) throws SAXException {
if(length != 0)
form.append(new String(ch,start,length));
}
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
//讀取username|email|company字段的值
if(qName.equals("username") || qName.equals("email")||qName.equals("company")){
form.append(qName);
//判斷屬性是否為空
int len = attributes.getLength();
if(len != 0){
for(int i = 0;i<len;i++){
form.append("("+attributes.getQName(i)+attributes.getValue(i)+")");
}
}
form.append(":");
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if(qName.equals("username") || qName.equals("email")||qName.equals("company"))
form.append("\n");
}
public void endDocument() throws SAXException {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -