aspose file tools*
The moose likes XML and Related Technologies and the fly likes Reading XML 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 "Reading XML" Watch "Reading XML" New topic
Author

Reading XML

Ravissant Saraswat
Greenhorn

Joined: Mar 15, 2010
Posts: 20
Hi Everyone,
Im working on an asset building assignment wherein I have to create a common search tool that can be plugged into any application without any code changes.
Now, for this I'm supposed to use an xml database and am currently writing a parser to build java objects out of the tables and fields .The problem I'm facing at present is that since the code needs to dynamic, the jsp side of the code needs to work in isolation from the parser ie., there isnt any table information present in the jsp . How do i reconcile the data from the jsp with the information I have stored of the database .
For your information, the xml database is provided and can have a standardized format.

Is what I'm suggesting possible or do I need to get some table information from the jsp too?

Please Help.

Thanks in advance,
Ravissant
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
Assuming I understand what you are trying to do. Why are you writing a parser instead of using the existing ones in the standard library?

The common way to work with XML in memory is to create a javax.xml.w3c.Document object which can be passed to whatever code needs it, such as a helper class for your JSP.

The XPath tools provide a handy way to specify and extract data from a Document object.

Where do you get the information on the desired JSP table output?

Bill

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Of course you shouldn't be doing any of this in a JSP. That's because JSPs should be limited to generating the view (the HTML) for the application. Heavy calculations are part of the model and the controller and should be done by servlets or by helper classes called from servlets.

However you mentioned an "XML database". Is this one of the products which advertise themselves as "XML databases" or is it just a collection of XML documents?

And when you say the code needs to be "dynamic", what does that mean? Often "dynamic" is a sloppy term meaning "something which has to be done at run-time", but of course your parsing needs to be done at run-time. The question is what is it which can't be configured in advance? Do you not know the schemas for the XML documents you will receive? Presumably you do know that because you said the database "can have a standardized format", so what exactly is "dynamic" here?

As for parsers, there are plenty of products which convert between XML and Java documents. Don't write another one unless your requirements are seriously peculiar.
Ravissant Saraswat
Greenhorn

Joined: Mar 15, 2010
Posts: 20
First of all, William and Paul thanks so much for your replies!
Im very new to parsing and the moment am getting by, by googling and asking experts like you. The thing is this, the moment I dont have anything , I've just written some xml that represents a few tables and have written a java class that extracts the table and field names and makes collection objects out of the tables with the fields as hashmap contents of the collection. These collections I intend passing to the query builder module.

By dynamic I mean there shouldnt be any hardcoding in the code.That is this search functionality code I'm developing should be pluggable into any application for any kind/nature/magnitute of search.

The XML Im using is very basic, which I intend building up on as I proceed, the following is an example:

The above representation has 2 tables employee and technology with 3 and 2 columns respectively.

Now, for the search functionality the jsp(at the moment) will send some data like employeename,technology etc like in any web search .This data needs to be collated with the database information I have in terms of collection objects.What I need to know is, does the information passed from the view need to be table/database specific? If no, how do I map the data(state, city etc) to the tables I have objects for?

Also, like I said Im new to parsing so could you please suggest a parser that I could use to serve my present purpose?

Thanks a lot!!
Ravissant
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Let me suggest this... there's a language called XPath which is a standard way of searching XML documents. It appears that you're trying to reinvent that, as well as most of the rest of the good old XML standards.
Ravissant Saraswat
Greenhorn

Joined: Mar 15, 2010
Posts: 20
... there's a language called XPath which is a standard way of searching XML documents


Hi Paul, If I'm not mistaken, isnt XPATH a client side language? .This isnt what I'm trying to achieve. I need a java class that does this and works in isolation from the jsp and is a seperate component altogether. The jsp provides the filtering data on the basis of which the query is to be built.

Thanks!
Ravissant
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Ravissant Saraswat wrote:Hi Paul, If I'm not mistaken, isnt XPATH a client side language?


I'm sorry, I don't understand what you mean by "client side language". I don't want to guess what kind of confusion led to this statement so let me just say there's an implementation of XPath in Java which works with DOM.
 
Don't get me started about those stupid light bulbs.
 
subject: Reading XML