I was working on one of the Xerces tutorials on this site. I tested one of the code pieces on an xml file, and got the following error:
java.lang.NoClassDefFoundError org/xml/sax/SAXNotSupportedException.
It compiled no problem, but apparently this error means that "The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found." I have installed all the xerces files and have set the classpath to my bin with all those files in it. How can it find the class def to compile, but not find it to run? And why is it giving me a sax error when I am using the dom? Very strange...Has anybody who tried the Xerces tutorials encountered this problem? Thanks in advance for your help.


import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import java.io.*;

public class MyThirdDomApp {

// a counter for keeping track of the "tabs"
private int TabCounter = 0;

// constructor
public MyThirdDomApp (String xmlFile) {

// create a Xerces DOM parser
DOMParser parser = new DOMParser();

// parse the document and
// access the root node with its children
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
NodeDetails(document);
} catch (Exception e) {
System.err.println (e);
}
}

// this is a recursive function to traverse the document tree
private void NodeDetails (Node node) {
String Content = "";
int type = node.getNodeType();

// check if element
if (type == Node.ELEMENT_NODE) {
FormatTree(TabCounter);
System.out.println ("Element: " + node.getNodeName() );

// check if the element has any attributes
if(node.hasAttributes()) {

// if it does, store it in a NamedNodeMap object
NamedNodeMap AttributesList = node.getAttributes();
// iterate through the NamedNodeMap and get the attribute names and values
for(int j = 0; j < AttributesList.getLength(); j++) {
FormatTree(TabCounter);
System.out.println("Attribute: " +
AttributesList.item(j).getNodeName() + " = " +
AttributesList.item(j).getNodeValue());
}
}
} else if (type == Node.TEXT_NODE) {

// check if text node and print value
Content = node.getNodeValue();

if (!Content.trim().equals("")){
FormatTree(TabCounter);
System.out.println ("Character data: " + Content);
}
} else if (type == Node.COMMENT_NODE) {
// check if comment node and print value
Content = node.getNodeValue();
if (!Content.trim().equals("")){
FormatTree(TabCounter);
System.out.println ("Comment: " + Content);
}
}

// check if current node has any children
NodeList children = node.getChildNodes();
if (children != null) {
// if it does, iterate through the collection
for (int i=0; i< children.getLength(); i++) {
TabCounter++;
// recursively call function to proceed to next level
NodeDetails(children.item(i));
TabCounter--;
}
}
}

// this formats the output for the generated tree
private void FormatTree (int TabCounter) {
for(int j = 1; j < TabCounter; j++) {
System.out.print("\t");
}
}

// the main method to create an instance of our DOM application
public static void main (String[] args) {
MyThirdDomApp MyThirdDomApp = new MyThirdDomApp ("SomeFile.xml");
}
}