76
|
1 package test;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.io.StringReader;
|
|
5
|
|
6 import javax.xml.parsers.ParserConfigurationException;
|
|
7 import javax.xml.parsers.SAXParser;
|
|
8 import javax.xml.parsers.SAXParserFactory;
|
|
9
|
|
10 import org.xml.sax.Attributes;
|
|
11 import org.xml.sax.InputSource;
|
|
12 import org.xml.sax.SAXException;
|
|
13 import org.xml.sax.helpers.DefaultHandler;
|
|
14
|
|
15 public class SessionXMLParser extends DefaultHandler{
|
|
16
|
|
17 public void startDocument() {
|
|
18 System.out.println("Start Document.");
|
|
19 }
|
|
20
|
|
21 public void startElement(String uri, String localName, String qName, Attributes attributes){
|
|
22
|
|
23 }
|
|
24
|
|
25
|
|
26 public static void main(String[] args) {
|
|
27 String string = null;
|
|
28 if(args.length > 0) {
|
|
29 string = args[0];
|
|
30 }
|
|
31 try {
|
|
32 SAXParserFactory spfactory = SAXParserFactory.newInstance();
|
|
33 SAXParser parser = spfactory.newSAXParser();
|
|
34 InputSource source = new InputSource(new StringReader(string));
|
|
35 parser.parse(source, new SessionXMLParser());
|
|
36 } catch (IOException e) {
|
|
37 // TODO Auto-generated catch block
|
|
38 e.printStackTrace();
|
|
39 } catch (ParserConfigurationException e) {
|
|
40 // TODO Auto-generated catch block
|
|
41 e.printStackTrace();
|
|
42 } catch (SAXException e) {
|
|
43 // TODO Auto-generated catch block
|
|
44 e.printStackTrace();
|
|
45 }
|
|
46 }
|
|
47
|
|
48 }
|