sax1.java~2~
来自「使用dom2,sax2解析xml,使用解析器生成、转化xml」· JAVA~2~ 代码 · 共 56 行
JAVA~2~
56 行
package xmloperation;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.util.*;
import java.io.*;
public class sax1 extends DefaultHandler
{
Stack tags = new Stack();
String name;
String address;
String tel;
String fax;
String email;
public sax1() {}
public void endDocument() throws SAXException
{
System.out.println("-----Parse End");
}
public void startDocument() throws SAXException
{
System.out.println("-----Parse Start");
}
public void startElement(String p0,String p1,String p2,Attributes p3) throws SAXException
{
tags.push(p2);
}
public void endElement(String p0,String p1,String p2) throws SAXException
{
tags.pop();
if(p2.equals("PERSON"))
{
printlnout();
}
}
public void characters(char[] p0,int p1,int p2) throws SAXException
{
String tag = tags.peek().toString();
if(tag.equals("NAME"))
{
name = new String(p0,p1,p2);
}
else if(tag.equals("NAME"))
{
name = new String(p0,p1,p2);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?