• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

runtime Error using SAX parser

Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.*;
import java.io.*;

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;
import java.io.*;

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>
Posts: 17344
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Posts: 11962
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!