Example: PullDeclaration

import org.xmlpull.v1.*;
import java.net.*;
import java.io.*;

 
public class PullDeclaration {

  public static void main(String[] args) {
        
    if (args.length == 0) {
      System.err.println("Usage: java PullDeclaration url" );
     return;    
    }
        
    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      XmlPullParser parser = factory.newPullParser();

      InputStream in;
      try {
        URL u = new URL(args[0]);
        in = u.openStream();
      }
      catch (MalformedURLException ex) {
          // Maybe it's a file name
          in = new FileInputStream(args[0]);
      }
      parser.setInput(in, null);
        
      for (int event = parser.next(); 
           event != XmlPullParser.START_TAG;
            event = parser.next()) ;
            
      String version = (String) parser.getProperty(
       "http://xmlpull.org/v1/doc/properties.html#xmldecl-version");
      Boolean standalone = (Boolean) parser.getProperty(
       "http://xmlpull.org/v1/doc/features.html#xmldecl-standalone");
      if (standalone == null) standalone = Boolean.FALSE;
      String encoding = parser.getInputEncoding();

      System.out.println("version=\"" + version + "\"");   
      System.out.println("standalone=\"" + standalone + "\"");   
      System.out.println("encoding=\"" + encoding + "\"");   
       
    }
    catch (XmlPullParserException ex) {
       System.out.println(args[0] + " is not well-formed");   
       System.out.println(ex);  
    }
    catch (IOException ex) {
      System.out.println(args[0] + " could not be checked due to an " 
       + ex.getClass().getName());   
      ex.printStackTrace();      
    }
        
  }

}

Previous | Next | Top | Cafe con Leche

Copyright 2000-2003 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified January 16, 2003