Results 1 to 4 of 4

Thread: XML Parser?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Resolved XML Parser?

    Does anyone know what name space i have to import in order to be able to use a SAXParser? Ive been reading an old book on xml that came out in June 2000. The author has stuff that looks like its been changed since. For instance he shows two imports and creates a new instance of a Parser.
    Code:
    import org.xml.sax.XMLReader;
    import org.apache.xerces.parsers.SAXParser;
    
    XMLReader parser = new SAXParser( );
    The import for the XMLReader seems to be correct but the SAXParser is in java.xml.parser. I would think the class SAXParser would be in the org.xml.sax namspace.

  2. #2

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: XML Parser?

    Weve got parsing! Not very fancy but i guess it's a start.
    Code:
    import java.io.IOException;
    import org.xml.sax.SAXException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.helpers.DefaultHandler; 
    import javax.xml.parsers.ParserConfigurationException;
    
    public class XMLP{
     public static void main(String[] args){
      if(args.length != 1){
       System.out.println("Usage [URI]"); 
       return; 
      }
      parseXML(args[0]); 
     }
     public static void parseXML(String uri){
      try{
      SAXParserFactory spf = SAXParserFactory.newInstance(); 
      SAXParser sp = spf.newSAXParser();
      sp.parse(uri, new DefaultHandler()); 
      }catch(IOException io){
        System.err.println(io);
      }catch(SAXException se){
        System.err.println(se);
      }catch(ParserConfigurationException pce){
        System.err.println(pce);
      }
     }
    }

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: XML Parser?

    I know you've already got it working, but I found a nice link that shows the import statements and stuff for different parsers.

    http://www.devx.com/xml/Article/16921/0/page/3

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width