View Javadoc

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 AllocEventParser {
15    private static String filename = null;
16    
17    private static void printUsage() {
18      System.out.println("usage: java com.bea.xml.stream.samples.AllocEventParse <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.XMLOutputFactory", 
31                         "com.bea.xml.stream.XMLOutputFactoryBase");
32      System.setProperty("javax.xml.stream.XMLEventFactory",
33                         "com.bea.xml.stream.EventFactory");
34      
35  
36      XMLInputFactory factory = XMLInputFactory.newInstance();
37      factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
38                        Boolean.FALSE);
39  
40      XMLEventReader r = 
41        factory.createXMLEventReader(new FileReader(filename));
42      while(r.hasNext()) {
43        XMLEvent e = r.nextEvent();
44        System.out.println("ID:"+e.hashCode()+"["+e+"]");
45      }
46    }
47  }
48  
49