📄 myhandler.java
字号:
package xmlparse;
import org.xml.sax.helpers.*;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
public class MyHandler extends DefaultHandler {
//XML开始部分调用该方法
public void startDocument() throws SAXException {
System.out.println("XML文档开始...........");
}
//XMl文件结束
public void endDocument() throws SAXException {
System.out.println("XML文档结束..........");
}
//读到文本对象的时候 调用
public void characters(char ch[], int start, int length) throws
SAXException {
String s = new String(ch, start, length);
if (!s.trim().equals(""))
System.out.println(s);
}
//读到元素的时候 调用
public void startElement(String uri, String localName,
String qName, Attributes attributes) throws
SAXException {
//元素的名字
System.out.print(qName);
//属性的名字和内容
for(int i=0;i<attributes.getLength();i++){
System.out.print (" " + attributes.getQName(i) +
"=" + attributes.getValue(i));
}
System.out.println();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -