1 package com.bea.xml.stream.samples;
2
3 import com.bea.xml.stream.StaticAllocator;
4 import java.io.FileReader;
5 import javax.xml.stream.*;
6 import javax.xml.stream.events.*;
7 import javax.xml.stream.util.*;
8 import javax.xml.namespace.QName;
9
10 /***
11 * @author Copyright (c) 2002 by BEA Systems. All Rights Reserved.
12 */
13
14 public class NoAllocEventParser {
15 private static String filename = null;
16
17 private static void printUsage() {
18 System.out.println("usage: java com.bea.xml.stream.samples.EventParse <xmlfile>");
19 }
20
21 public static void main(String[] args) throws Exception {
22 try {
23 filename = args[0];
24 } catch (ArrayIndexOutOfBoundsException aioobe){
25 printUsage();
26 System.exit(0);
27 }
28 System.setProperty("javax.xml.stream.XMLInputFactory",
29 "com.bea.xml.stream.MXParserFactory");
30 System.setProperty("javax.xml.stream.XMLEventFactory",
31 "com.bea.xml.stream.EventFactory");
32
33 XMLInputFactory factory = XMLInputFactory.newInstance();
34 XMLEventAllocator allocator = new StaticAllocator();
35 factory.setEventAllocator(allocator);
36 XMLEventReader r =
37 factory.createXMLEventReader(new FileReader(filename));
38 while(r.hasNext()) {
39 XMLEvent e = r.nextEvent();
40 System.out.println("ID:"+e.hashCode()+"["+e+"]");
41 }
42 }
43 }
44
45