• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Reading XML

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 28323
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28323
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

... 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
Sheriff
Posts: 28323
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Skool. Stay in. Smartness. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic