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

How and where to use xml

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Hi everybody, I am Krishna, I don't know can I ask this question here.

I am reading xml since days and I am unable o understand what for it is used. can anybody tell me where in real time I use xml.

All I know is, a client will send a request and server will process the request, issue a query to database and retrieve the dara and print the data to the response and send the web page to client. This is time consuming, so server will retrieve the data from database in xml file format and send it to the client. Now using javascript client will parse the xml file and show the data.

Is this correct?

And one more thing is when I was searching to learn AJAX, on some web pages I saw this code



After that the client will stripeoff the name tag and represent the data. My question is why can't the serve directly send the data like


I saw some code like this in some sites

<?xml version="1.0"?>


who is going to write this document, is it the database or the programmer. If the programmer has to write this code, then what about if another par is introduced, how many times the programmer has to change the xml document. or if the server retreives the data from database in xml format then how it is going to send the file from server to client. how the javascript opens the file.

Can anybody please help me with XML, I reffered w3schools and many more sites, but I didn't understood where and how can I use XML.

Thank you all in advance. Have a nice day.


There is no rule that we all should know everything. Lets learn few things of everything here.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

I think you are confused about the usage of AJAX in web applications.

All I know is, a client will send a request and server will process the request, issue a query to database and retrieve the dara and print the data to the response and send the web page to client. This is time consuming, so server will retrieve the data from database in xml file format and send it to the client. Now using javascript client will parse the xml file and show the data.

Is this correct?


Not entirely correct. But assuming you are asking this question in the context of AJAX - it's mainly about asynchronous requests. You will find a lot of documentation around AJAX, through a quick search. This gives a quick overview (the "Rationale" section in there will answer some of your questions).

[My Blog] [JavaRanch Journal]
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Thank you Jaikiran, acutally I wasn't able to explain my doubt, no problem, I will give a try again.

I wrote a AJAX code such that it contacts the server and retrieves a xml file named books, suppose in future if few more books are added, then ultimately the xml file must be changed by the programmer, suppose if daily few books are added then what about the xml file.

So what I want to do is, I will call a jsp, which will connect to database, then retrieve the data in xml file, then I will send this xml file to client, the AJAX code will parse the xml file and represent the data.

Is this possible? calling a jsp then retrieving a xml file, and representing the data, is this possible? If possible please tell me where can I find the complete solution, why because I am unable to find this is any site.

Thank you in advance. Have a nice day.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

krishna anusha wrote:I wrote a AJAX code such that it contacts the server and retrieves a xml file named books, suppose in future if few more books are added, then ultimately the xml file must be changed by the programmer, suppose if daily few books are added then what about the xml file.

No, of course the programmer isn't sitting next to the server and typing the XML. There would be some code on the server which generates the XML based on some data it gets from somewhere.
So what I want to do is, I will call a jsp, which will connect to database, then retrieve the data in xml file, then I will send this xml file to client, the AJAX code will parse the xml file and represent the data.

Is this possible? calling a jsp then retrieving a xml file, and representing the data, is this possible? If possible please tell me where can I find the complete solution, why because I am unable to find this is any site.

Actually you left out some steps there. It's not likely your code will retrieve XML from the database. More likely it will retrieve ordinary data from the database and construct an XML document from that data. Then yes, you would return that XML document as the response and the AJAX code would deal with it.

The other step you left out is, you wouldn't do most of that in a JSP. You would do the data extraction in a servlet and then forward to the JSP, which would generate XML from the data.

So yes, of course it's possible. But if you were hoping to find a complete solution on the internet, you aren't going to find that. You will certainly find tutorials on various topics, like database processing and XML and so on. But there aren't people out there writing tutorials on combinations of three or more topics, like you were hoping.

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Thank you Paul, now I understood something, but there is still some confusion, but I have a program without any servlet, as a beginner and just for simulation I wrote this in a jsp page, please don't mind. Here is the code and the objective is to find the existence of an employee id. If employee id already exists false is returned, otherwise true is returned.

Here is the select_id.jsp page.

Can you tell me how to use xml here. Please just tell me the model. I will be very thankful to you and thanks in advance. Have a nice day.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How and where to use xml