📄 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 + -