Q: |
When I try to run XMLReader, I get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: XMLReader |
A: |
The problem is probably with your $CLASSPATH variable. By default, the working directory is included in your CLASSPATH, that is until you define CLASSPATH yourself. Then you need to add it yourself. Here's the line from my .cshrc file that works: setenv CLASSPATH /usr/class/cs108/jar/jaxp.jar:/usr/class/cs108/jar/crimson.jar:. |
Q: |
I get deprecation warnings when I compile. Is this okay? |
A: |
Yes, it happens because of the aforementioned .jar files, there's not a lot you can do about it. |
Q: |
The homework says to remove whitespace from our output, but in the sample file there's whitespace in the middle of the lines. What do we do about this. |
A: |
You need not do a thing. Run .trim on your output, but you're not responsible for whitespace in the middle of lines. |
Q: |
Is any xml file valid? Or can we expect that only the xml file given will be valid? |
A: |
Yes, the homework just states that an xml file will be given. You can assume a valid xml file will be given, however. |
Q: |
What do we do about xml files like this: <node1 description="XML file"> <node2> <node3 title="Something"> Some other text here. </node3> <node2> Text Inserted Here </node1> |
A: |
This is a valid xml file, based on the xml definition. The "Text Inserted Here" text belongs to the "node1" node But don't despair, read on... |
Q: |
What do we do if both a child and a parent node matches the search string? |
A: |
Since the handout is not clear, you may interpret it any way you see fit, ie you could print both the child and the parent, or just the parent, or even just the child. If two peers match the string, then yes, you should print out the text for both of them. So in the case of the xml above, if the user searched on "text," a correct response could be: <node1> description=XML file Text Inserted Here or you could output: <node1><node2><node3> title=Something Some other text here So once a child matches the text, you can forget about any text that belongs to the parent node. If once a parent node has the matching text, you can forget about all child nodes, use either/both interpretations as you need to in order to make the assignment simpler. NOTE: It is possible to make your program find all the matches in both parent and children if you take a "store all nodes on a stack" based approach. Basically, don't worry about calling "new" too much, we're not looking for efficiency with this assignment, and it's pretty easy to do if you store nodes, attributes, text correctly as you go along. |
Q: |
Are there any docs for the SAX parser? |
A: |
Read the end of the handout, the url is: http://java.sun.com/xml/jaxp-1.1/docs/api/index.html |
Q: |
In my startElement handler, I'm trying to store the Attributes/AttributeList, but I'm getting weird results. What's going on? |
A: |
You probably have a handler like this: public void startElement (String name, AttributeList attrs) throws SAXException { my_attr = attrs; } The problem is the SAX framework, in order to be as efficient as possible, will reuse that attrs object which you have a reference to. In order to get around this problem you need to make a persistant copy of the AttributeList or Attributes object. Look in the docs at the AttributesImpl and AttributeListImpl classes to see how to do this. |