File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes runtime Error using SAX parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "runtime Error using SAX parser" Watch "runtime Error using SAX parser" New topic

runtime Error using SAX parser

Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37

I am using the following code to parse an XML called as order.xml.
I am using SAX parser to do so.
i have set the class path for JAXP.jar and Parser.jar in my class path.
The code is compiling fine but when i execute the code its giving an error.

C:\javaexamples>java ExtractorDriver order.xml
org.xml.sax.SAXException: System property org.xml.sax.driver not specified

It says "System property org.xml.sax.driver not specified".

Can any one let me know how to over come the error.


import org.xml.sax.*;

public class TextExtractor implements ContentHandler {

private Writer out;

public TextExtractor(Writer out) {
this.out = out;

public void characters(char[] text, int start, int length)
throws SAXException {

try {
out.write(text, start, length);
catch (IOException e) {
throw new SAXException(e);


// do-nothing methods
public void setDocumentLocator(Locator locator) {}
public void startDocument() {}
public void endDocument() {}
public void startPrefixMapping(String prefix, String uri) {}
public void endPrefixMapping(String prefix) {}
public void startElement(String namespaceURI, String localName,
String qualifiedName, Attributes atts) {}
public void endElement(String namespaceURI, String localName,
String qualifiedName) {}
public void ignorableWhitespace(char[] text, int start,
int length) throws SAXException {}
public void processingInstruction(String target, String data){}
public void skippedEntity(String name) {}

} // end TextExtractor

import org.xml.sax.*;
import org.xml.sax.helpers.XMLReaderFactory;

public class ExtractorDriver {

public static void main(String[] args) {

if (args.length <= 0) {
"Usage: java ExtractorDriver url"

try {
XMLReader parser = XMLReaderFactory.createXMLReader();

Writer out = new OutputStreamWriter(System.out);
ContentHandler handler = new TextExtractor(out);


catch (Exception e) {




<?xml version="1.0" encoding="ISO-8859-1" ?>
- <Order>
<Customer id="c32">Chez Fred</Customer>
- <Product>
<Name>Birdsong Clock</Name>
<Price currency="USD">21.95</Price>
- <ShipTo>
<Street>135 Airline Highway</Street>
<Subtotal currency="USD">263.40</Subtotal>
<Tax rate="7.0" currency="USD">18.44</Tax>
<Shipping method="USPS" currency="USD">8.95</Shipping>
<Total currency="USD">290.79</Total>
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Pooja, welcome to Javaranch.

I need to move this thread to a more appropriate forum. This forum is for Servlets question. Your question is about SAX and XML.

Also there is a set of buttons under the Add Reply button when creating a thread or a reply. These buttons can really help with formatting. The one that says "CODE" can create tags that wrap around code and it will keep its format/tabbing/and spacing, to make nice and easy to read code.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Do you have a SAX parser implementation in your classpath?
If it is, and the XMLReaderFactory still complains about the system property missing, I guess you need to add it yourself (java ... -Dorg.xml.sax.driver=com.parser.impl.BlahBlah ... MyApplication).

PS. it's better to use the javax.xml.parsers.SAXParserFactory class from JAXP instead of the older XMLReaderFactory.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: runtime Error using SAX parser
It's not a secret anymore!