• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

XMLReader versus SAXParser

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a series of SAX2 applications that use the constructor SAXParser() to create an instance of the parser.
XMLReader reader = new SAXParser();
These applications work fine.
The O'Reilly book on Java and XML indicates that this class (SAXParser) implements the org.xml.sax.XMLReader interface (pg. 50). If I change my code to use XMLReader instead of SAXParser, I get a ClassNotFoundException: org.apache.xerces.parsers.SAXParser.
Here's the code line that changed:
XMLReader parser = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser");
Can anyone explain to me why? This problem is also causing me troubles when trying to use Xalan.
 
Kevin Newsom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm touching this in the hopes of someone seeing it at the top of the list. I'm really stumped on this problem.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it work if you use SAXParserFactory.newSAXParser() ??
 
Kevin Newsom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I got this to work by implanting the code from XMLReaderFactory into my parsing class. In particular the line:
return (XMLReader)(Class.forName(className).newInstance());
doesn't throw a class not found exception when it is within 'my' class that parses the document.
I still don't know why it wouldn't work before.
I still think I have a problem when using Xalan but we'll see.
 
Kevin Newsom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it working in the manner that it should. I had to place the appropriate jar files in the lib/ext folder. Having them in the class path didn't seem to cut it.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic