File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes SAX newbie question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "SAX newbie question." Watch "SAX newbie question." New topic
Author

SAX newbie question.

lupercal hill
Greenhorn

Joined: Sep 28, 2005
Posts: 9
Can I use SAX to read the values of this file into a ListArray of objects. With the same

private int idNumber;
private int correctAttempts;
private int incorrectAttempts;
private int location;
private String englishWord;
private String foreignWord;





Also Why is using XML better then RandomFile class. I cant see any immediate advantages.

David Patterson
Ranch Hand

Joined: Jul 01, 2002
Posts: 65
Yes, using the SAX approach, you can write a program to read the XML file and store the data in a ListArray (or any other collection) of Card objects with the members you show. Using SAX, you write a class to process the data, and get called at three main methods -- startElement, endElement, and characters.

Why XML? In my opinion, on of the big reasons is that you can validate your input before you start. If you were to do a good job on the program above, you would have to worry about what happens if one card did not have a location, or if a card had two enghishwords. What if someone created a file with

<CorrectAttempts>one</CorrectAttempts>

There are lots of ways someone could create a such a file that could cause problems to your program. If you were to describe the proper content (using something called XML Schema) then the sender could check before sending to make sure the input was correct, and you could check before processing the file that it was "proper". You can specify the sequence of elements, how often they occur, and what kind of content is valid.

The difficulty between writing a commercial-grade program to read an unvalidated file vs. a validated one is very large. To process a validated file, the job is much easier.

Is XML the answer to all data interchange problems? No. Can it be force fit into situations for which it is a lousy answer? Of course. Like all technologies, it needs to be used in the right places and avoided in the wrong places.

Dave Patterson
Ric Luper
Greenhorn

Joined: May 15, 2005
Posts: 9
Thank you for the advice Dave . I learned some JAVA about 3 years ago then put it down. This helps alot.

I wish to update the cards using a GUI, depending on wether they are answered correctly or not. From doing more reading it seems that DOM is better suited for this. Is that right?
David Patterson
Ranch Hand

Joined: Jul 01, 2002
Posts: 65
DOM is a good bet.

Dave Patterson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SAX newbie question.