If you are not familiar with a lot of XML-related APIs, the easiest approach is to use the SAX API, in my opinion*.

1) Write a SAX event handler (receives events when XML elements are opened, closed, and when text values of attributes and elements are encountered -- you assemble your objects as the events arrive)
2) Configure a SAXParserFactory
3) Use the factory to create a SAXParser
4) Register your event handler with the parser
5) Create an input source from your XML file and connect it to the parser
6) Tell the parser to parse


This is a streaming-style "push" technique -- you read the file from start to finish, caching whatever you are interested in. If you need random access (to be able to read in forward and reverse) to the file, take a look at DOM -- which is used for loading and holding an entire document in memory. I've never found a use for it.

Another technique that is used, for example, in Jabber packet handling libraries, is pull parsing. Pull parsing is similar to push parsing except (to be very basic here) you can tell the parser to seek the part of the document you are interested in, rather than handle a bunch of events you aren't interested in.

* There are higher level APIs that might suit you better, depending on what you are doing. Struts and Commons Validator use some sort of higher-level "config" library, if I'm not mistaken, that is designed for constructing objects/Maps out of config files, so you might have a look at the source code for one or both of those. I'm sure someone else could on the list could better inform you about this.

Erik



[EMAIL PROTECTED] wrote:

Struts does not have a specific support for XML, but you can use inside a
webapp all the libraries that you normally use under classic applications.
For example, if you want to load a DOM for an XML file inside an action
(not very elegant...), you can use DOM4J (or similar libraries).
If you want to use XML files inside JSP pages you can use the xtags, and
so on.
Ciao
Antonio Petrelli



Hi all,

How can i read XML files using struts? is this possible? Can any one


provide


a link or give an example for reading XML files using struts?

:-)


Jay










---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to