-
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. :confused:
-
Re: XML Parser?
Weve got parsing! :D Not very fancy but i guess it's a start. :thumb:
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);
}
}
}
-
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
-
Re: XML Parser?
Thanks System_Error ill check it out. :)